Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winforms 使用gridview(Devexpress Winform)过滤后的getdatasourcerowindex nullreference?_Winforms_C# 4.0_Devexpress_C# 3.0 - Fatal编程技术网

Winforms 使用gridview(Devexpress Winform)过滤后的getdatasourcerowindex nullreference?

Winforms 使用gridview(Devexpress Winform)过滤后的getdatasourcerowindex nullreference?,winforms,c#-4.0,devexpress,c#-3.0,Winforms,C# 4.0,Devexpress,C# 3.0,我正在使用gridview-devexpress。在该组件上使用过滤器后,会出现错误nullreference。如果我不使用过滤器。我的代码没有错误 for (int i = 0; i < GridView1.RowCount; i++) { DataRow dr; dr = GridView1.GetDataRow(GridView1.GetDataSourceRowIndex(i));

我正在使用gridview-devexpress。在该组件上使用过滤器后,会出现错误nullreference。如果我不使用过滤器。我的代码没有错误

        for (int i = 0; i < GridView1.RowCount; i++)
        {
            DataRow dr;
            dr = GridView1.GetDataRow(GridView1.GetDataSourceRowIndex(i));
            MessageBox.Show(dr[0].ToString());

        }

这是我的密码。过滤后从gridview获取数据行值的任何解决方案?

问题可能在于您使用的是行计数。DataSourceRowIndex基于基础数据源持有的索引。那不一样。如果正在分组或排序,gridview的行句柄将发生更改。而RowCount只显示GridView中有多少行。但这不能等同于您的datasourceindex

尝试以下操作以获取数据行:

一,

您必须知道RowCount属性不能用于安全访问行

如果您需要进一步的帮助,请不要犹豫询问。

您必须使用属性而不是属性:

for (int i = 0; i < GridView1.DataRowCount; i++)
{
    DataRow dr;
    dr = GridView1.GetDataRow(GridView1.GetDataSourceRowIndex(i));
    MessageBox.Show(dr[i].ToString());
}

您使用哪种过滤器?您是在筛选DataRow还是gridview?您使用的是rowfilter还是哪个过滤器?@Sebi在gridview上。在devexpres上的组件gridview中,有ShowautofilterRow,我在gridview上使用它。在devexpres上的组件gridview中,有ShowautofilterRow,我使用它。如果我在那个组件上使用过滤器,那么如果我使用函数getdatasourcerowindex,gridview上的数据总是空的。当然可以。您无法访问GridView.RowCount并尝试访问具有该索引的数据源。如果使用ShowAutoFilterRow=true,gridview将在gridview顶部显示filterrow。此autofilterrow将由GridView.RowCount索引。但在您的数据源中,该索引不会有任何行。您的数据源中没有filterrow。我的例子有用吗?否则,请张贴您是如何创建网格的。@Sabi感谢您的关注,但我有我的代码。这是我的解决方案。`DataRowView dr=DataRowViewGridView1.GetRowGridView1.GetVisibleRowHandlei;MessageBox.Showdr[0].ToString`
for (int i = 0; i < GridView1.DataRowCount; i++)
{
    DataRow dr;
    dr = GridView1.GetDataRow(GridView1.GetDataSourceRowIndex(i));
    MessageBox.Show(dr[i].ToString());
}