代码之家  ›  专栏  ›  技术社区  ›  Dean Harry

RadGridView是否获取子模板数据?

  •  0
  • Dean Harry  · 技术社区  · 10 年前

    我试图在网格中迭代时只获取子模板的数据。

    我从以下内容开始:

            foreach (GridViewRowInfo row in radGridView1.Rows)
            {
                err = IterateChildRows(row);
            }
    

    并将该行传递给:

        private bool IterateChildRows(GridViewRowInfo rowInfo)
        {
            bool err = false;
            if (rowInfo.Cells[5].Value != null && rowInfo.Cells[5].Value.ToString() != "01/01/1900")
            {
                if (rowInfo.Cells[0].ViewTemplate.Templates[0].Caption == "Current")
                {
                    if (rowInfo.ViewTemplate.Templates[0].RowCount == 0)
                    {
                        MessageBox.Show("Not all products have CURRENT quantity breaks", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        err = true;
                    }
                }
            }
            return err;
         }
    

    我的问题是,我似乎找不到我传递的行的子模板数据。我所尝试的一切似乎都有来自所有主模板项的所有子行,而不仅仅是我传递的行。

    因此,如果我在主网格中有2个项目,在子模板中各有3个项目,那么我得到的计数是6而不是3。

    我不知道我哪里出错了。。。

    任何人

    干杯 院长

    1 回复  |  直到 10 年前
        1
  •  1
  •   Bayeni    10 年前

    尝试以下操作,可以通过HierarchyRowInfo访问子行

    private bool IterateChildRows(GridViewRowInfo rowInfo)
    {
        bool err = false;
        GridViewHierarchyRowInfo hierarchyRow = rowInfo as GridViewHierarchyRowInfo;
    
        //To get current row childRows count
        int noOfChildRows = hierarchyRow.ChildRows.Count;
    
        //looping through the child rows
        foreach (GridViewRowInfo row in hierarchyRow.ChildRows)
        {   
            //check if its current child row
            if(row.IsCurrent)
            {
               // Do your logic
            }
        }
    
        return err;
     }