You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取DataView中被RowFilter过滤掉的数据集

获取DataView过滤后被排除的记录集合

Got it, let's break down how to grab the records that got filtered out of your DataView. The core idea is to compare the full set of rows from the original table against the rows that are visible in the filtered DataView—then the difference is exactly what you need.

Step-by-Step Solution

Here's a clean, LINQ-based approach:

  • First, get all rows from the original underlying table of your DataView.
  • Then extract the rows that are visible in the filtered DataView (since DataView contains DataRowView objects, we'll map them back to their original DataRow instances).
  • Use the Except method to find rows that exist in the full table but not in the visible set—those are your excluded records.

Full Code Example

// Assume your DataView is stored in this variable
DataView filteredView = data as DataView;

// Get all rows from the original table
var allTableRows = filteredView.Table.AsEnumerable();

// Get only the rows that are visible in the filtered DataView
var visibleRows = filteredView.Cast<DataRowView>()
                              .Select(rowView => rowView.Row);

// Calculate the excluded records (full table minus visible rows)
var excludedRecords = allTableRows.Except(visibleRows);

Bonus: Convert Excluded Records to a DataTable

If you need the excluded records in a new DataTable (instead of just an enumerable), you can use:

DataTable excludedTable = excludedRecords.CopyToDataTable();

Why This Works

  • DataRowView.Row directly references the original DataRow from the table, so the Except method can accurately compare references to find the missing rows.
  • This approach avoids duplicating your original RowFilter logic manually, making it maintainable and efficient.

内容的提问来源于stack exchange,提问作者Adhi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:54:57