ComboBox contents change detection

Sep 4, 2009 at 4:04 PM

I have a list of values in a combobox in a cell and I want to detect when the user has chosen a different value from the selection available.

I am currently detecting changes in OnValueChanged(...) but this only triggers when the focus goes to another cell, i.e. they have to click elsewhere for the change to be inplemented.

What do I have to override so that as soon as the user clicks on the new selection in the dropdown I can implement thier choice?

Many Thanks


Sep 6, 2009 at 6:26 AM

You have to subscribe to the combo box event of value changed. Now you are subscribing to cells event. So, naturally, cell only fires this event when combobox accepts users change.  I believe there should be a "Control" property on the cell, which you probably could cast down to ComboBox control

Sep 7, 2009 at 8:31 AM

Yes, you are right.  Sometimes I miss the obvious answer!

For anyone else thinking about this, here is what I did to get it working

I added this to handle the event:

editorComboCustomDisplay.Control.SelectionChangeCommitted += new EventHandler(Control_SelectionChangeCommitted);

and got the value like this:

void Control_SelectionChangeCommitted(object sender, EventArgs e)
    ComboBox thisBox = (ComboBox)sender;
    double theValueIWant = Convert.ToDouble(thisBox.SelectedItem);

Nice and easy ;o)


Oct 8, 2009 at 2:07 AM
Edited Oct 8, 2009 at 2:11 AM

Hi Davd:

i have same question.

can list the Details?  editorComboCustomDisplay = how Declared?

 SourceGrid.Cells.Controllers.CustomEvents comboxEvent;

comboxEvent = new SourceGrid.Cells.Controllers.CustomEvents();
comboxEvent.Click += new EventHandler(Control_SelectionChangeCommitted);


is it, right? but it can't run.

Thank you.     skype: lindawang123


Oct 8, 2009 at 8:56 AM

Hi Linda,

The editorComboCustomDisplay in my code is declared as follows

            SourceGrid.Cells.Editors.ComboBox editorComboCustomDisplay = new SourceGrid.Cells.Editors.ComboBox(typeof(Decimal), arrayRealVols, false);
            editorComboCustomDisplay.Control.FormattingEnabled = true;
            editorComboCustomDisplay.EditableMode = EditableMode.SingleClick | EditableMode.AnyKey | EditableMode.Focus;
            editorComboCustomDisplay.Control.DropDownStyle = ComboBoxStyle.DropDownList;
            DevAge.ComponentModel.Validator.ValueMapping comboMapping = new DevAge.ComponentModel.Validator.ValueMapping();
            comboMapping.DisplayStringList = arrayVols;
            comboMapping.ValueList = arrayRealVols;
            comboMapping.SpecialList = arrayVols;
            comboMapping.SpecialType = typeof(string);

            editorComboCustomDisplay.Control.SelectionChangeCommitted += new EventHandler(Control_SelectionChangeCommitted);
            this[1, 0] = new SourceGrid.Cells.Cell(arrayRealVols[4], editorComboCustomDisplay);
            this[1, 0].Editor = editorComboCustomDisplay;
            this[1, 0].AddController(eventController);

            this[1, 0].View = SourceGrid.Cells.Views.ComboBox.Default;

arrayVols and arrayRealVols are arrays of data to put into the comboBox that I have declared and filled elsewhere in my code. 

I think I got all this code from the examples included with the code.  That is a very good source to find out how things work.

Hope that helps


Oct 9, 2009 at 1:38 AM

hi, David:

 i got it, and Thank you~   ^^