public static void dgvCellEditing(DataGridView dgv,string columnName, DataGridViewEditingControlShowingEventArgs e) { if (dgv.CurrentCell != null && dgv.CurrentCell.ColumnIndex == dgv.Columns[columnName].Index) { Control cntObject = new Control(); e.Control.TextChanged += new EventHandler((object sse, EventArgs se) => Utilities.Cell_TextChanged(sse, dgv, cntObject)); cntObject = e.Control; cntObject.TextChanged += (object sse, EventArgs se) => Utilities.Cell_TextChanged(sse, dgv, cntObject); } dgv.RefreshEdit(); }
// ================================================================================= // Forcing a DataGridview display update // Ugly hack if you ask me, but MS didn't give us any other reliable way... private void Update_GridView(DataGridView Grid) { Grid.CommitEdit(DataGridViewDataErrorContexts.Commit); BindingSource bs = new BindingSource(); // create a BindingSource bs.DataSource = Grid.DataSource; // copy jobdata to bs DataTable dat = (DataTable)(bs.DataSource); // make a datatable from bs Grid.DataSource = dat; // and copy datatable data to jobdata, forcing redraw Grid.RefreshEdit(); Grid.Refresh(); }