Display multi line text as one item in a listbox

A

ashwath

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:[email protected]
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
 
G

Guest

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:[email protected]\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
 
C

Chris Shepherd

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top