Home Forums WinForms controls Xceed Grid for WinForms Detect combobox change Reply To: Detect combobox change

User (Old forums)
Post count: 23064

This works, but if you want to get the selected item value event while the editor is active, you can also use the following method, which is in fact the recommended way when using editors in the grid.

What you need is to use the ActivatingControl and DeactivatingControl events, which are triggered when the editor actually becomes active in the grid (and when it stops being active). You get an handle of the editor in the event, and you can do anything with it, like subscribing to its events. In this example, you subscribe to the SelectedItemChanged event, which will permit you to be notify of any changes while the editor is active.

e.g. :

//setup the ComboBoxEditor
<i> gridControl1.Columns[ “column1” ].CellEditorManager = new ComboBoxEditor( dataSet11.Shippers, “”, “ShipperID”, “%CompanyName%” );
gridControl1.Columns[ “column1” ].CellViewerManager = new ComboBoxViewer( dataSet11.Shippers, “”, “ShipperID”, “%CompanyName%” );
//subscribe to the events
<i> gridControl1.Columns[ “column1” ].CellEditorManager.ActivatingControl += new CellEditorEventHandler(CellEditorColumn1_ActivatingControl);
gridControl1.Columns[ “column1” ].CellEditorManager.DeactivatingControl += new CellEditorEventHandler(CellEditorColumn1_DeactivatingControl);

//Event handlers
private void CellEditorColumn1_ActivatingControl(object sender, CellEditorEventArgs e)
( ( WinComboBox )e.Control).SelectedItemChanged += new EventHandler(ComboBoxColumn1_SelectedItemChanged);

private void ComboBoxColumn1_SelectedItemChanged(object sender, EventArgs e)
string item = ( ( WinComboBox )sender).SelectedValue.ToString();
System.Diagnostics.Debug.WriteLine( item );

private void CellEditorColumn1_DeactivatingControl(object sender, CellEditorEventArgs e)
</i> //need to unsubscribe to the event, so it does not keep piling up in the ActivatingControl event
<i> ( ( WinComboBox )e.Control).SelectedItemChanged -= new EventHandler(ComboBoxColumn1_SelectedItemChanged);

Imported from legacy forums. Posted by André (had 3985 views)