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

后端 未结 4 870
Happy的楠姐
Happy的楠姐 2021-01-02 15:05

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

4条回答
  •  再見小時候
    2021-01-02 15:47

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

提交回复
热议问题