Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

Display multi line text as one item in a listbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ashwath - 17 Sep 2007 11:50 GMT
Hi,

I am relatively new to Windows forms, i am using a listbox to show
items in Compact Framework 2.0. I want to display something of this
sort

Name: John                                    Email:j...@gmail.com
Phone:9817239821                         Sex:Male

This whole text should appear as one item in the list box.
I tried giving "\n" in the text, but it is showing a square box.
Should i use an owner drawn listbox? If so, how do I display the
enter, newline??

Thanks in advance,
Ashwath
Mihaly - 17 Sep 2007 13:40 GMT
Hi,
Try this:
Create a class like above:

class ListItem
{
public object Id = null;
public string Text = null;

public ListItem(object id, string text)
{
this.Id = id;
this.Text = text;
}

public override string ToString()
{
return this.Text;
}
}

When you added the line to listbox you will use

this.listBox1.Items.Add(new ListItem(1,
"Name:Jhon\tE-mail:mail@gmail.com\tPhone:+40298123456\tSex:Male"));

Ehen you get the selected line in the listbox, you will use

id = ((ListItem) this.listBox1.SelectedItem).Id;

Hope this is help you.
Mihaly

> Hi,
>
[quoted text clipped - 12 lines]
> Thanks in advance,
> Ashwath
Chris Shepherd - 17 Sep 2007 19:11 GMT
> This whole text should appear as one item in the list box.
> I tried giving "\n" in the text, but it is showing a square box.
> Should i use an owner drawn listbox? If so, how do I display the
> enter, newline??

Did you try System.Environment.Newline instead of \n? Technically a new
line is denoted by \r\n on Windows Hosts, not just \n.

Chris.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.