Link to home
Start Free TrialLog in
Avatar of TMPSupport
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(object sender, System.EventArgs e)
            {
                  lstStoredProcedures.Items.Clear();
                  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();
                        tspTableProcedures.addStoredProcedures(_arStoredProcedures);
                        _arTableStoredProcedures.Add(tspTableProcedures);
                  
                        foreach(StoredProcedure spProcedure in _arStoredProcedures)
                        {      
                              lstStoredProcedures.Items.Add(spProcedure.ProcedureName);
                              //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
Avatar of quoclan
quoclan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TMPSupport
TMPSupport

ASKER

Thanks quoclan...