turn fromhttps://maodaili.de/mao.php?u=a%2FMrbEvUE8PnCuc7FrhJi0Rqd3kmOBHPZUbcJ1c2hbJUK0RYWpAf4lhIOddItP% 2bki2z5pzeivpy%3d&b=15Some related applications of datagridviewcomboboxcolumn in DataGridView (i) triggering an event when its value changesCategory: Form2008-07-23 23:27 2451 people read reviews (4) favorite reports Objectbutton today in Csdn back to a post to see a DataGridView problem, need to trigger the event in DataGridViewComboBoxCell to be able to solve.
Open vs test did not find can directly trigger the DataGridViewComboBoxCell in the ComboBox in the value of the event, depressed for half a day, look closely at MSDN there is a solution to the example, all blame themselves did not look carefully:
You first need to trigger the first event: currentcelldirtystatechanged
And calling the Datagridview.commitedit method in the event [about Commitedit MSDN explains the following: commits the changes in the current cell to the data cache, but does not end the edit mode. ]
So that the event that we care about cellvaluechanged can be triggered smoothly.
Call the following MSDN the source code provided for this workaround is for reference only:)
This event handler manually raises the Cellvaluechanged event//by calling the Commitedit method.void datagridview1_cur Rentcelldirtystatechanged (object sender, EventArgs e) {if (datagridview1.iscurrentcelldirty) {Datagridvie W1. Commitedit (Datagridviewdataerrorcontexts.commit); }}//If A check box cell is clicked, this event handler disables//or enables the button in the same row as the clicked cell.public void Datagridview1_cellvaluechanged (object sender, DataGridViewCellEventArgs e) {if (datagridview1.colum Ns[e.columnindex]. Name = = "checkboxes") {DataGridViewDisableButtonCell Buttoncell = (datagridviewdisablebuttoncell) dat AGridView1. Rows[e.rowindex]. cells["Buttons"]; Datagridviewcheckboxcell Checkcell = (Datagridviewcheckboxcell) dataGridView1. Rows[e.rowindex]. cells["checkboxes"]; buttoncell.enabled =! (Boolean) Checkcell.value; Datagridview1.invalidate (); }}