【问题标题】:WPF DataGrid - make column readonly via c#WPF DataGrid - 通过c#使列只读
【发布时间】:2023-03-19 17:37:01
【问题描述】:

我正在尝试通过 c# 关闭 WPF Datagrid 单元格的 isReadOnly 属性。一旦用户点击一行,我就需要这样做。

到目前为止我有这个

 private void dgProductItem_PreviewMouseDown(object sender, MouseButtonEventArgs e)
 {
     DataGrid dg = sender as DataGrid;

     if (dg != null)
     {
        DataGridRow dgr = (DataGridRow)(dg.ItemContainerGenerator.ContainerFromIndex(dg.SelectedIndex));
     }
  }

但是我如何通过

数据网格行

所以最后我在寻找 cell.ISReadOnly = false/true;

干杯

【问题讨论】:

  • 你想让列只读?
  • 我在 XAML 中将列设置为只读 = true,但是,在特定行上我想将其更改为 false

标签: c# wpf datagrid


【解决方案1】:

如果您想处理 DataGridCell 对象,您需要的代码比预期的要多一些

Check the answer here 并使用TryTofindGridCell 方法检索DataGridCell 对象,然后设置其IsreadOnly 属性

或者,您也可以检查solution described here 以检索DataGridRows / DataGridCell

【讨论】:

  • 对于其他人的信息:我使用了第二个链接 + 当您在 Xaml 上声明 isReadOnly 时,要使其不是只读的,请使用 cell.IsEditing 因为 cell.isReadOnly 只是一个 getter!
猜你喜欢
  • 1970-01-01
  • 2011-01-30
  • 2020-05-21
  • 1970-01-01
  • 2021-07-09
  • 2011-01-03
  • 2016-04-28
  • 2015-11-19
  • 1970-01-01
相关资源
最近更新 更多