public static bool DataGridViewPaste(DataGridView dgv, DataGridViewCellEventHandler dgv_CellValueChanged) { //粘贴赋值 dgv.CellValueChanged -= dgv_CellValueChanged; //string errMessage = MyMethod.PasterToDataGridView(dgv, dgv.AllowUserToAddRows, ref rowsCount, ref columnsCount); //string errMessage = MyMethod.PasterToDataGridView(dgv, false, ref rowsCount, ref columnsCount); DataGridViewBehaviors.PasterToDataGridView(dgv, true); //再绑定单元格值改变事件 dgv.CellValueChanged += dgv_CellValueChanged; return(true); }
public static void DataGridViewCut(DataGridView dgv, DataGridViewCellEventHandler dgv_CellValueChanged) { if (dgv_CellValueChanged != null) { dgv.CellValueChanged -= dgv_CellValueChanged; } DataGridViewBehaviors.CopyFromDataGridView(dgv); foreach (DataGridViewCell item in dgv.SelectedCells) { if (dgv.Columns[item.ColumnIndex].ReadOnly) { continue; } item.Value = DBNull.Value; } //再绑定单元格值改变事件 if (dgv_CellValueChanged != null) { dgv.CellValueChanged += dgv_CellValueChanged; } }