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.