|
-
Jul 26th, 2006, 01:54 AM
#1
Thread Starter
Member
[RESOLVED] [2005] Problem with ComboBox_SelectedIndexChanged event
I have ComboBox bound to DataTable (Lookup table) and I have some code in ComboBox_SelectedIndexChanged event. I want that code to be executed when user select value from ComboBox.
Problem is that ComboBox_SelectedIndexChanged event fired on form load which I dont want, I expect it to be fired only when user pick item in combobox.
How to avoid ComboBox_SelectedIndexChanged event to be fired on form load?
-
Jul 26th, 2006, 02:06 AM
#2
Re: [2005] Problem with ComboBox_SelectedIndexChanged event
 Originally Posted by dranko
How to avoid ComboBox_SelectedIndexChanged event to be fired on form load?
You can't. The event is raised when the SelectedIndex property changes. Think outside the square a bit. In the event handler, test whether the Load event handler has already been executed. You would do that by setting a boolean flag at the end of the Load event handler.
-
Jul 26th, 2006, 02:41 AM
#3
Thread Starter
Member
Re: [2005] Problem with ComboBox_SelectedIndexChanged event
Yes, that works.
My problem is in my thinking that SelectedIndex changed only when I click on ComboBox and pick item, but obviously I was wrong.
Thanks
-
Jul 26th, 2006, 02:51 AM
#4
Re: [2005] Problem with ComboBox_SelectedIndexChanged event
When you set the DataSource property of the ComboBox it automatically selects the first item. If you don't want the first item selected you have to explicitly set the SelectedIndex to -1, but that means two SelectedIndexChanged events rather than none.
-
Jul 26th, 2006, 03:07 AM
#5
Thread Starter
Member
Re: [2005] Problem with ComboBox_SelectedIndexChanged event
I like your answers because you give explanation how something works (not only solution), and I learned a lot from you.
Thanks.
-
Jul 27th, 2006, 01:58 PM
#6
Member
Re: [RESOLVED] [2005] Problem with ComboBox_SelectedIndexChanged event
I was having this same issue. You want to use the SelectionChangeCommitted event as that will only respond to the user change on the control, not a program change of a index.
-
Jul 28th, 2006, 12:40 AM
#7
Thread Starter
Member
Re: [RESOLVED] [2005] Problem with ComboBox_SelectedIndexChanged event
Eh, why didn't I read help more carefully.
"SelectionChangeCommitted is raised only when the user changes the combo box selection. Do not use SelectedIndexChanged or SelectedValueChanged to capture user changes, because those events are also raised when the selection changes programmatically."
Thanks.
-
Jul 28th, 2006, 12:44 AM
#8
Re: [RESOLVED] [2005] Problem with ComboBox_SelectedIndexChanged event
New information for me too.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|