c# - 如何在我的 DataGrid 中获取选定单元格的当前列(C# WPF 应用程序)
问题描述
我想用 RowFilter 过滤我的 DataGrid。用户应该能够通过选择一个单元格来选择他的列。比他把一些文本放在一个文本框中,他可以过滤数据网格。我尝试了一些东西,但它们没有用。也许我可以在这里得到一些帮助 :) 我会很高兴收到每一个回复。这是我的代码和我尝试过的事情:
private void Filter_Click(object sender, RoutedEventArgs e)
{
DataView DV1 = DT1.DefaultView; // DT1 is my DataTable-Object
// DV1.RowFilter = "Column1 = '" + Filter.Text + "'"; This works fine
DV1.RowFilter = "'" + DataGrid1.CurrentCell.Column+ "' = '" + Filtern.Text + "'"; // When i try this it doesnt work
DataGrid1.ItemsSource = DV1;
}
我尝试了其他一些命令:DataGrid1.CurrentCell.Column.DisplayIndex 或 DataGrid1.CurrentCell.Column.Header 或 DataGrid1.CurrentColumn 但我总是得到一个错误。指挥部给了我一个 0。也许有人有想法?
解决方案
尝试这个:
DataGrid1.SelectedCells[0].ColumnIndex
0 是选择的第一个元素
推荐阅读
- java - 有没有办法将java maven文件导入php
- javascript - 使用 sort() 提供 repos 列表
- javascript - 如何使用javascript计算两个不同的表?
- python-3.x - 如何在 Python 中排除或删除特定部分
- spring - 有时会发生断管。重复此错误(无限重复),然后tomcat重新启动
- c# - 在 Azure Pipeline 和 Linux 上构建 .Net Framework
- php - 通过 PHP Curl 进行谷歌翻译
- apache-spark - 是否有 Spark Arrow Streaming = Arrow Streaming + Spark Structured Streaming?
- entity-framework - 实体框架准备查询
- reactjs - React TypeScript:路线位置和子属性的正确类型