By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,461 Members | 2,184 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,461 IT Pros & Developers. It's quick & easy.

ListBox On Click Event

P: 14
Hi all

I wrote a listbox onclick event.On a click i want to get the selected row details but the listbox.selected(i) always returns false ,it returns true only in
double click event.Are they any other events on which i could do this.I want to populate a textbox based on the row selected from the listbox.Its working as i want when i add the code in a double click event but it doesn't make much sense doing it on a double click event.

thanks
Sree
Jan 26 '09 #1
Share this Question
Share on Google+
5 Replies


missinglinq
Expert 2.5K+
P: 3,532
The standard method for doing this sort of thing uses the AfterUpdate event of the listbox (or combobox) not the Click or DoubleClick event.

Welcome to Bytes!

Linq ;0)>
Jan 26 '09 #2

P: 14
missinglinq

I tried that too.Didn't work either.the listbox.selected returns false in any event except in double click evnt.

thanks
Sree
Jan 26 '09 #3

missinglinq
Expert 2.5K+
P: 3,532
This type of thing is normally done without using the Selected property at all, something like this.

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourListBoxName_AfterUpdate()
  2.      Me.TextBox1 = Me.YourListBoxName.Column(0)
  3.      Me.TextBox2 = Me.YourListBoxName.Column(1)
  4.      Me.TextBox3 = Me.YourListBoxName.Column(2)
  5. End Sub
Note that the columns are Zero-based, so the first column (reading left-to-right) would be column(0), the second column(1) and so forth.

When you click on a row to select it the textboxes are filled in.

Linq ;0)>
Jan 26 '09 #4

P: 14
All

Got it worked using listbox.listIndex property instead of listbox.Selected property on OnClick event


thanks for ur help
Sree
Jan 26 '09 #5

missinglinq
Expert 2.5K+
P: 3,532
Glad you got it working. The Selected Property is intended to be used when the Listbox Multi-Select Property is set to either Simple or Extended. You use it to loop thru all rows to see which are selected. It's really not meant to be used in your type of application.


Linq ;0)>
Jan 26 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.