我有一个DataGrid
链接到一个DataTable
.
在这个 DataGrid 中,我自己在后面的代码中添加了 3 列。
if (resultDataGrid.ItemsSource != null)
{
List<String> resColList = new List<String> { "Solde M.O", "Solde Deplacement", "Solde Pieces" };
foreach (string cName in resColList)
{
DataGridTextColumn column = new DataGridTextColumn();
column.Header = cName.ToUpper();
column.Binding = new Binding(cName.ToUpper());
resultDataGrid.Columns.Add(column);
}
}
我想重新索引这个DataGrid
包含 19 列的列,但问题是当我对我的DataGrid
列进行计数时,即使我DataGrid
得到了我DataTable
的 as ,它也只计算后面代码中添加的 3 列ItemSource
。
if (_tableCase.Rows.Count > 0)
{
resultDataGrid.ItemsSource = _tableCase.AsDataView();
createResultColumn();
setColumnIndex(); //This is the fonction which set the new index.
}
else
resultDataGrid.ItemsSource = null;
MessageBox.Show(resultDataGrid.Columns.Count.ToString()); //this return 3 first run and then 31 if I change the filter.
for (int i = 0; i < resultDataGrid.Columns.Count; ++i) // Only display the 3 column added in the code behind.
MessageBox.Show(resultDataGrid.Columns[i].Header.ToString());
但是当在我的应用程序中更改显示中的行的过滤器时DataTable
,DataGrid
现在我的列数返回 31。
有人对我错过了什么有任何解释吗?因为经过数小时的调试,什么都没有出现。