c# - "SelectedIndexChanged" event in ComboBoxColumn on Datagridview -
I want to handle this event on a DataGridViewComboBoxColumn "SelectedIndexChanged", and I fixed it "EditingControlShowing" event gridview Have done Issue: The "SelectedIndexChanged" event is not removed on the first attempt of selecting an item in the combo box, but the item is selected for the second time after the event is removed And everything works fine Here is the code: The circumstances became complicated because they all The data grid view has been optimized for rows by just one edit control. Here's how I have controlled the situation like this: Hook up a representative for the first EditControlShowing event: Then the handler, EditControl the SelectedValueChanged event up to the hook:
private void dgvRequest_EditingControlShowing (object sender, DataGridViewEditingControlShowingEventArgs e) e.Control as {ComboBox combo = ComboBox; if (! Combo = null) {if (dgvRequest.CurrentCell.ColumnIndex == col_ConfirmCmb.Index) {combo.SelectedIndexChanged - = combo_ConfirmSelectionChange; Combo Selected Index changed + = Select Combo Confirm selection; Return; }}} Void combo_ConfirmSelectionChange (object sender, EventArgs e) {if (! DgvRequest.CurrentCell.ColumnIndex = col_ConfirmCmb.Index) return; Combo box combo = sender as combo box; If (combo == empty) return; MessageBox.Show (combo.SelectedText); // tap for the first time}
myGrid.EditingControlShowing + = New DataGridViewEditingControlShowingEventHandler (Grid_EditingControlShowing); ...
void Grid_EditingControlShowing (object sender, DataGridViewEditingControlShowingEventArgs e) {ComboBox combo = E. Control in the form of a combo box; If (combo! = NULL) {// combo changes Iventhandr combo Diliget = new Iventhandlr ((Sibisender, Arjis) = & gt; {DOSomeStuff ();}) event handling; // Register the event with the Edit Control Combo. Selected value change + = combo dialegate; // Since we do not want to add this event many times, when // edit control is hidden, we have to remove the handler that we had added. EventHandler visibility output = Null; Visibility Delegate = New EventHandler ((Viger, Args) = & gt; {// remove the handler when the editing control // is no longer visible. (If the vendor as a control). Visual == incorrect) { Combo.SelectedValueChanged - = comboDelegate; VisSender.VisibleChanged - = Visibility Delegate;}}); (Sender as DataGridView) .EditingControl.VisibleChanged + = Delegate Visibility; }}
Comments
Post a Comment