如何在devexpress的datagridview中使特定的列可编辑复制
本文关键字:复制 编辑 devexpress datagridview | 更新日期: 2023-09-27 18:13:45
我有devexpress datagridview,有10列,第一列作为名称,这是不可编辑的,但用户应该能够复制单元格内容(名称)。
private void gridViewBatches_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
{
GridView view = sender as GridView;
if (view.FocusedColumn.FieldName == "Batch No") //Editable true
{
e.Cancel = false;
} else //Other column editble false
{
e.Cancel = true;
}
}
一种解决方案是更改列的ReadOnly
或AllowEdit
选项。
其他解决方案是使用视图的ShowingEditor
事件,并通过使用事件处理程序的e.Cancel
参数的代码禁用单元格编辑。
//Disable updating on the entire grid
uGrid1.DisplayLayout.Override.AllowUpdate = DefaultableBoolean.False;
// Disable the first column in the first band
ultraGrid1.DisplayLayout.Bands[0].Columns[0].CellActivation = Activation.Disabled;
// Disable the first cell in the grid
uGrid1.Rows[0].Cells[0].Activation = Activation.Disabled;
ultraGrid1.DisplayLayout.Bands[0].Columns[0].CellActivation = Activation.Disabled;
更新:
以下解决方案适用于评论中确认的Amol,包括这里的其他人受益。
private void gridViewBatches_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
{
GridView view = sender as GridView;
if (view.FocusedColumn.FieldName == "Batch No") //Editable true
{
e.Cancel = false;
} else //Other column editble false
{
e.Cancel = true;
}
}