more combobox fun

more combobox fun

Old forum URL: forums.lhotka.net/forums/t/2933.aspx


ajj3085 posted on Tuesday, May 22, 2007

Hi all,

I'm having a problem.  I have a UserControl, which has a combobox on it.  The text property is bound to a property on my BO, which is fine.  The BO is a child of another BO, which is edited by the main form.

The problem I'm having is that the SelectedIndexChanged event fires unexpected; basically, the form containing the usercontrol has its MdiParent property set, and this for some reason is causing the SelectedIndexChanged event to fire.

I need code to run UNLESS the control is loading, and this works fine... except for this unexpected event.

Any idea why this is happening?

Thanks
Andy

Jav replied on Tuesday, May 22, 2007

Andy,

I have been doing Web development for the last year, but I remember being plagued with this same problem when working in WinForms.  I am sure you are enclosing you code with "If SelectedIndex > -1".  As I recall when you set up the ComboBox DataSource, the SelectedIndex by itself changes to zero - which will make it barge right into your code. Is it possible that your combobox is firing in response to the datasource being set? 

I also remeber that my ComboBoxes behaved much better when I set up the DisplayMember and the ValueMember properties first - before setting up the DataSource property.

Jav

ajj3085 replied on Wednesday, May 23, 2007

Jav,

Yes, I did run into the problem of setting the datasource for the combobox and having that reset the index.  I handled that by having an isLoading flag, which I set while I'm setting up the data sources.

This is occuring because for some reason the event is firing again when the MdiParent property of the form is set.. I've confirmed this by looking at the call stack.  The odd thing is that this doesn't happen on my other forms, it just seems to happen on this form where I have a user control on the form (which itself is on a UltraTabPage). 

With other comboboxes I've been pretty successful in using them and setting DisplayMember and the Datasource via the designer.  The trick is when you actually fill in the proper datasource, you turn off binding events, set teh DS, then turn them on, and finally call ResetBindings( false ).  that normally works pretty well..

Andy

Copyright (c) Marimer LLC