add an item to a listbox

S

Sam

Hi,
How can I add an item to a listbox so that when we select an item
afterward, we'll get the id associate, like the display member and the
value member for a combobox ?


regards
 
R

Ryan Chavez

Oh I think I can answer this one!

To add an item:
m_pListBox.Items.Add("Item 1")

To get the selected item:
Private Sub m_pListBox_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles m_pListBox.Click
Dim iIndex as Integer = m_pListBox.SelectedIndex
Dim o as Object = m_pListBox.Items(iIndex)
End Sub

Hope that answers your question.

Ryan
 
S

Sam

That wasn't the question actually....
Anyway, this is what I wanted to do but it didn't work only because I
had a spell error in my valuemember field.... :(


lstFields.DataSource = m_dsCtrl.Tables(0)
lstFields.DisplayMember = "FieldName"
lstFields.ValueMember = "FieldID"
 

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