Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListBox more than 1 display member

Status
Not open for further replies.

ludmann

Programmer
Apr 14, 2004
49
0
0
GB
I have a dataset/datatable and trying to get it to get the rows of the table to display in a ListBox.

My code so far

String disp = dt_shared.Columns["FirstName"].ToString() + " " + dt_shared.Columns["LastName"].ToString();

listBox1.DataSource = dt_shared;
listBox1.DisplayMember = disp;
listBox1.ValueMember = "Email1Address";
listBox1.DataBindings.Add("SelectedValue",dt_shared,"Email1Address");

dt_shared is the datatable and I am trying to first attempt display the FirstName, LastName and EmailAddress on one line,
Second attempt (which is not shown here), also display other attributes in the table as part of the Display member.

I thought if I can create a string disp, then I can just assign this to DisplayMember and get FirstName, LastName and EmailAddress Displayed.

However, it is only displaying the last element (EmailAddress) in the ListBox.

How can I have more than one display member?

Marika
 
Having the dt_shared DataTable object populated you can do the followings:
Code:
DataColumn dc =new DataColumn("disp");
dt_shared.Columns.Add(dc);
foreach DataRow dr in dt_shared.Rows()
{
   dt_shared.Columns["disp"]= dt_shared.Columns["FirstName"].ToString() + "  " + dt_shared.Columns["LastName"].ToString() +dt_shared.Columns["Email1Address"].ToString();
}
         
listBox1.DataSource = dt_shared;
listBox1.DisplayMember = "disp";
listBox1.ValueMember = "Email1Address";
-obislavu-
 
I have just about figured out that this is what I have to do. However, the user will also have to see a lot more attributes of the Contact. Specifically the attributes that are to be updated, to decide wether to go ahead or not.

like
John Smith - j.smith@oracle.com
21July1977
23 Compayne Gardens
LONDON
SMTP
Jane Buldock - jane@homent.co.uk
NW7

So I thought maybe I could bind the ListBox to another control like a ListView. When eg. John Smith is selected in the ListBox, then the ListView would display the other attributes 21July1977 etc.

The attributes beside the name, that I plan to display in a listView vary each time. It could be 1 attribute, or it could be 20. So I need a conrol that is always the same size. Like a scrollable ListView (I hope there is such thing)

Would you know how to bind the listBox and ListView together, so the listView always displays the related attributes?

Marika
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top