繁体   English   中英

如何在C#中的devexpress的datagridview中使特定列可编辑以进行复制?

[英]how to make particular column editable for copy in datagridview of devexpress in c#?

我有devexpress datagridview有10列与第一列作为名称,这是不可编辑的,但用户应该能够复制单元格content(Name)。

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;
    }
}

一种解决方案是更改列的ReadOnlyAllowEdit选项。

其他解决方案是使用视图的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;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM