zoukankan      html  css  js  c++  java
  • Dev GridView 获取选中分组下的所有数据行 z

    现在要在DevExpress 的GridView 中实现这样一个功能。就是判断当前的选中行是否是分组行,如果是的话就要获取该分组下的所有数据信息。

    如下图(当选中红框中的分组行事。程序要获取该分组下的所有数据)


    实现代码如下:

     List<int> _gridViewRowIndexs = new List<int>(); //存储GridView 中选中的行索引
    
            private void Test()
            {
                int[] rows = gridView1.GetSelectedRows(); //获取GridView 选中的数据行信息
                for (int i = 0; i < rows.Count(); i++)
                    _gridViewRowIndexs = FildRowsNotGroupIndex(rows[i]);
            }
    
            //获取分组下面的所有数据行索引(针对有多级分组的情况)
            private List<int> FildRowsNotGroupIndex(int rowIndex)
            {
                List<int> returnValue = new List<int>();
                bool isGroup = gridView1.IsGroupRow(rowIndex);//判断当前的行索引是否是分组行
                if (isGroup == false)
                {
                    returnValue.Add(rowIndex);
                }
                else
                {
                    int count = gridView1.GetChildRowCount(rowIndex);//获取当前分组下的数据个数
                    for (int j = 0; j < count; j++)
                    {
                        int childRowIndex = gridView1.GetChildRowHandle(rowIndex, j);//获取当前分组下的第i条记录的行索引
                        returnValue.AddRange(FildRowsNotGroupIndex(childRowIndex).ToArray());
                    }
                }
    
                return returnValue;
            }
    

     获取的行索引_gridViewRowIndexs  是GridView 中的行索引。如果要获取绑定数据源的行索引。

    int dataTableIndex = gridView1.GetDataSourceRowIndex(item);  //将 GridView 中的行索引转化成 绑定数据源中的行索引
    
  • 相关阅读:
    VS code 配置 PySide6的UI开发环境
    Python及PySide6学习网址
    NOIP2021模拟赛10.12 题解
    P2388 阶乘之乘 题解
    P3992 [BJOI2017]开车
    「NOIP2021模拟赛四 B」Polyline 题解
    P7115 [NOIP2020] 移球游戏 题解
    P7114 [NOIP2020] 字符串匹配 题解
    P3391 【模板】文艺平衡树 题解
    致夏天
  • 原文地址:https://www.cnblogs.com/zeroone/p/4176884.html
Copyright © 2011-2022 走看看