Setting the ValueMember of a listbox in Windows Forms...
Posted on 2006-04-14
I have been doing everything in asp.net lately so I am struggling with this simple issue in a Windows Forms Application. In Asp.net I would create a ListItem and then add it to the listbox
ex.. ListItem li = new ListItem("DisplayValue", "ValueMember);
and then with my list box
In windows forms the ListBox.Add() method does not accept a ListItem.
I do not have a DataTable that I can bind to the listbox and use something that looks like this...
lstItems.DataSource = dtItems;
lstItems.DisplayMember = "DisplayColumn";
lstItems.ValueMember = "ValueColumn";
I am using the add method and I'm trying to set the ValueMember with no success... I will post the code that I am attempting to execute...
private void btnGetProcedures_Click(object sender, System.EventArgs e)
ListBox.SelectedIndexCollection indexes = lstTables.SelectedIndices;
foreach (int index in indexes)
int iTableID = getTableID(lstTables.Items[index].ToString());
_intTableID = iTableID;
TableStoredProcedures tspTableProcedures = new TableStoredProcedures(_intTableID);
_arStoredProcedures = GetStoredProcedures();
foreach(StoredProcedure spProcedure in _arStoredProcedures)
//This is where i need to set the value member...
All i need is to set the ValueMember when setting the DisplayMember...
If anyone can help the question is worth 500pts...
Thanks in advance...