在运行时编辑DataGridView HeaderCell文本

时间:2018-11-08 20:11:23

标签: c# wpf data-binding datagridview datagrid

我正在使用以下方法加载WPF数据表:

ETL = GetTable(table);
DataGridView.DataContext = ETL;

一旦我可以在View中看到数据,我希望能够在运行时更改列标题。更改标头的值会触发其他事件,这些事件会将更改保存到配置文件中。

我找不到一种方法可以检测到标题上的右键单击,找出当前列是什么并编辑值。

在调试的同时,我认为我在此事件上取得了进步:

private void DataTable_RightClick(object sender, MouseButtonEventArgs e)
{
    var temp = e.OriginalSource;
}

如果单击标题,e.OriginalSource.DataContext是字符串,但是单击单元格,则{System.Data.DataRowView}。我尝试使用该信息作为var temp = e.OriginalSource.DataContext;,但收到错误消息:

CS1061  C# 'object' does not contain a definition for 'DataContext' and no accessible extension method 'DataContext' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

所以我也尝试了MouseButtonEventArgs temp = e.OriginalSource.DataContext;,但是没有运气。

有什么提示吗?

0 个答案:

没有答案
相关问题