简体   繁体   中英

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

One solution is to change ReadOnly or AllowEdit options of your columns.

Other solution is to use the ShowingEditor event of the view and disable cell editing via code using the event handler's e.Cancel parameter.

Here is the code snippet:

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

Update :

Following solution works for Amol as confirmed in comments, including here for others benefit.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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