当前位置:网站首页>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
边栏推荐
- Detailed explanation of the use of staticlayout
- 学习笔记6--卫星定位技术(上)
- WorkManager學習一
- 驱动制造业产业升级新思路的领域知识网络,什么来头?
- The Alipay in place function can't be found, and the Alipay in place function is offline
- @JsonAdapter注解使用
- Swift saves an array of class objects with userdefaults and nssecurecoding
- [论文阅读] CKAN: Collaborative Knowledge-aware Atentive Network for Recommender Systems
- Energy momentum: how to achieve carbon neutralization in the power industry?
- Timed disappearance pop-up
猜你喜欢
Design of stepping motor controller based on single chip microcomputer (forward rotation and reverse rotation indicator gear)
How does redis implement multiple zones?
Swift tableview style (I) system basic
Energy momentum: how to achieve carbon neutralization in the power industry?
B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条...
What is the most suitable book for programmers to engage in open source?
Uni app running to wechat development tool cannot Preview
Constrained layout flow
Constraintlayout officially provides rounded imagefilterview
最全是一次I2C总结
随机推荐
驱动制造业产业升级新思路的领域知识网络,什么来头?
面试:List 如何根据对象的属性去重?
Glide conclusion
[paper reading] kgat: knowledge graph attention network for recommendation
ConstraintLayout的流式布局Flow
Pseudo class elements -- before and after
重磅:国产IDE发布,由阿里研发,完全开源!
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
Tianlong Babu TLBB series - about items dropped from packages
Atcoder beginer contest 254 "e BFS" f st table maintenance differential array GCD "
学习笔记4--高精度地图关键技术(下)
到底谁才是“良心”国产品牌?
Swift tableview style (I) system basic
How does redis implement multiple zones?
【观察】跨境电商“独立站”模式崛起,如何抓住下一个红利爆发时代?
AtCoder Beginner Contest 254「E bfs」「F st表维护差分数组gcd」
Excerpt from "sword comes" (VII)
LiveData 面试题库、解答---LiveData 面试 7 连问~
@SerializedName注解使用
非技术部门,如何参与 DevOps?