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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie listbox question 1

Status
Not open for further replies.

no1biscuit

Programmer
Oct 8, 2001
67
US
Ok no laughing (out loud that is).

I am filling a simple list box. I am wanting to get the valuemember of the selected row. Why is this so hard???? Sample code would be great.

Thanks
Thom
 
How are you filling the listbox? Could you post some code?



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Here is my code.

Dim sql as String = "select * from tblalarms"
Dim da as SqlDataAdapter(
Dim dt as Datatable
da = New SqlDataAdapter(sql, dbconn)
dt = New DataTable
da.Fill(dt)
lstalarms.Datasource = dt
lstalarms.DisplayMember = "description"
lstalarms.ValueMember = "address"
lstalarms.SelectedIndex = -1


 
Ok, you should be able to access the value member by using ListBox1.SelectedValue (with a listbox named ListBox1).

Is this not working for you?


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Next question. How do I prevent it from firing selectedindexchanged when the form loads? Or is there a way to see if it was the form load causing it or if the user actually clicked one of the values?
 
You can create a boolean variable that is global to the form:

Dim bLoading As Boolean


The in the Form_Load event handler:

bLoading = True

'do your loading stuff

bLoading = False


Then in the SelectedIndexChanged event handler:

If Not bLoading Then

'do your stuff

End If


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top