TMPSupport
asked on
Setting the ValueMember of a listbox in Windows Forms...
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
lstItems.Add(li);
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(obj ect sender, System.EventArgs e)
{
lstStoredProcedures.Items. Clear();
ListBox.SelectedIndexColle ction indexes = lstTables.SelectedIndices;
foreach (int index in indexes)
{
int iTableID = getTableID(lstTables.Items [index].To String());
_intTableID = iTableID;
TableStoredProcedures tspTableProcedures = new TableStoredProcedures(_int TableID);
_arStoredProcedures = GetStoredProcedures();
tspTableProcedures.addStor edProcedur es(_arStor edProcedur es);
_arTableStoredProcedures.A dd(tspTabl eProcedure s);
foreach(StoredProcedure spProcedure in _arStoredProcedures)
{
lstStoredProcedures.Items. Add(spProc edure.Proc edureName) ;
//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...
Rick
ex.. ListItem li = new ListItem("DisplayValue", "ValueMember);
and then with my list box
lstItems.Add(li);
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(obj
{
lstStoredProcedures.Items.
ListBox.SelectedIndexColle
foreach (int index in indexes)
{
int iTableID = getTableID(lstTables.Items
_intTableID = iTableID;
TableStoredProcedures tspTableProcedures = new TableStoredProcedures(_int
_arStoredProcedures = GetStoredProcedures();
tspTableProcedures.addStor
_arTableStoredProcedures.A
foreach(StoredProcedure spProcedure in _arStoredProcedures)
{
lstStoredProcedures.Items.
//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...
Rick
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER