我有devexpress datagridview,其中包含10列,第一列为Name,不可编辑,但用户应该能够复制单元格内容(名称)。
答案 0 :(得分:1)
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;
}
}
答案 1 :(得分:0)
一种解决方案是更改列的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;
}
}