当前位置:网站首页>C#实现获取DevExpress中GridView表格进行过滤或排序后的数据
C#实现获取DevExpress中GridView表格进行过滤或排序后的数据
2022-07-05 10:15:00 【牛奶咖啡13】
一、需求描述
当前我们的业务中需要获取对DevExpress中GridView表格进行过滤或排序后的数据内容。
二、需求分析
直接获取GirdView表格的数据内容是最开始绑定的内容,不会跟随表格控件过滤或排序后而改变;我们可以直接遍历表格的内容填充到新DataTable中返回。
三、实现方法
#region 获取表格过滤或排序后的数据
/// <summary>
/// 获取GridView过滤或排序后的数据集
/// </summary>
/// <typeparam name="T">泛型类对象</typeparam>
/// <param name="gridView">gridView组件</param>
/// <returns></returns>
public static IEnumerable<T> GetFilterOrSortDatasOfGridView<T>(DevExpress.XtraGrid.Views.Grid.GridView gridView) where T : class
{
var list = new List<T>();
for (int i = 0; i < gridView.RowCount; i++)
{
if (gridView.IsGroupRow(i))
continue;
var entity = gridView.GetRow(i) as T;
if (entity == null)
continue;
list.Add(entity);
}
return list;
}
/// <summary>
/// 获取GridView过滤或排序后的数据集
/// </summary>
/// <param name="gridView">gridView组件</param>
/// <returns></returns>
public static DataTable GetFilterOrSortDatasOfGridView(DevExpress.XtraGrid.Views.Grid.GridView gridView)
{
DataTable _dt = gridView.GridControl.DataSource as DataTable;
if (_dt == null) return null;
DataTable dt = _dt.Clone();
for (int i = 0; i < gridView.RowCount; i++)
{
if (gridView.IsGroupRow(i))
continue;
var dr = gridView.GetDataRow(i);
if (dr == null)
continue;
dt.Rows.Add(dr.ItemArray);
}
return dt;
}
#endregion 边栏推荐
- 【Vite】1371- 手把手开发 Vite 插件
- Go项目实战—参数绑定,类型转换
- Singleton mode encapsulates activity management class
- 驱动制造业产业升级新思路的领域知识网络,什么来头?
- AtCoder Beginner Contest 258「ABCDEFG」
- leetcode:1200. 最小绝对差
- ConstraintLayout的流式布局Flow
- Who is the "conscience" domestic brand?
- CSDN always jumps to other positions when editing articles_ CSDN sends articles without moving the mouse
- 官网给的这个依赖是不是应该为flink-sql-connector-mysql-cdc啊,加了依赖调
猜你喜欢
![C language QQ chat room small project [complete source code]](/img/4e/b3703ac864830d55c824e1b56c8f85.png)
C language QQ chat room small project [complete source code]

"Everyday Mathematics" serial 58: February 27

Redis如何实现多可用区?

A large number of virtual anchors in station B were collectively forced to refund: revenue evaporated, but they still owe station B; Jobs was posthumously awarded the U.S. presidential medal of freedo

mongoDB副本集

AtCoder Beginner Contest 258「ABCDEFG」

学习笔记4--高精度地图关键技术(下)

Design of stepping motor controller based on single chip microcomputer (forward rotation and reverse rotation indicator gear)

Events and bubbles in the applet of "wechat applet - Basics"

How to plan the career of a programmer?
随机推荐
Z-blog template installation and use tutorial
Unity particle special effects series - the poison spray preform is ready, and the unitypackage package can be used directly - next
@JsonAdapter注解使用
[paper reading] kgat: knowledge graph attention network for recommendation
"Everyday Mathematics" serial 58: February 27
Zblogphp breadcrumb navigation code
Qt实现json解析
Swift saves an array of class objects with userdefaults and nssecurecoding
Fluent generates icon prompt logo widget
爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
php解决redis的缓存雪崩,缓存穿透,缓存击穿的问题
驱动制造业产业升级新思路的领域知识网络,什么来头?
Redis如何实现多可用区?
The horizontally scrolling recycleview displays five and a half on one screen, lower than the average distribution of five
TypeError: Cannot read properties of undefined (reading ‘cancelToken‘)
Unity particle special effects series - the poison spray preform is ready, and the unitypackage package is directly used - on
SqlServer定时备份数据库和定时杀死数据库死锁解决
SLAM 01.人类识别环境&路径的模型建立
Timed disappearance pop-up
【Vite】1371- 手把手开发 Vite 插件