Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I specify which Columns are editable in a WPF DataGrid?

I have a WPF 4.0 DataGrid with AutoGenerated columns. I would like to only allow the user to edit the first column. Is there an easy way of doing this?

I was trying to add a DataGridCell style and set it's editing ability based on either ColumnName (1st column always has the same name) or ColumnIndex, however I cannot figure out the correct XAML for this, or even if it is possible.

like image 872
Rachel Avatar asked Dec 17 '10 15:12

Rachel


1 Answers

The below sample does the trick for one or more columns

  private void Grid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
    {
        if (e.Column.Header.ToString() == "COLUMNNAME")
        {
            // e.Cancel = true;   // For not to include 
            // e.Column.IsReadOnly = true; // Makes the column as read only
        }

    } 
like image 165
BMG Avatar answered Sep 29 '22 11:09

BMG