devExpress

GridControl 之 BandedGridView合并单元格 隔行换色html教程

时间:2013/6/19 23:42:24  作者:WPF之家  来源:http://www.wpf123.com  查看:110  评论:0
内容摘要:对于设置AllowMerged=false的BandedGridView隔行换色很简单,直接设置Apperence.EvenRow和OddRow的样式就可以,可是当AllowMerged=true时,发现这些设置就没有用了,要想隔行换色,就得自己动手了,本人想了个简单办法如下,就...

对于设置AllowMerged=false的BandedGridView隔行换色很简单,直接设置Apperence.EvenRow和OddRow的样式就可以,可是当AllowMerged=true时,发现这些设置就没有用了,要想隔行换色,就得自己动手了,本人想了个简单办法如下,就是在BandedGridView的RowCellStyle事件中设置:

              首先,当然是需要得到哪些是偶数行,哪些时奇数行,这里我就设置偶数行BackColor,奇数行不变,首先你必须得到偶数行的RowHandle,注意此偶数行非系统RowHandle,因为合并单元格后,只不过看起来成了一行,但是系统不会区分,所以你就得把合并的行看成一行,下面方法是我用来得到偶数行RowHandle的方法:

        public static List<int> GetEvenRowHandle(GridView gv)
        {
            int j = 0;//这里是我们自己定义的行号 
            List<int> evenRowHandle = new List<int>();
            object lastValue = null;
            GridViewInfo vInfo = gv.GetViewInfo() as GridViewInfo;//取到所有行信息
            for (int i = 0; i < vInfo.RowsInfo.Count; i++)
            {
                GridDataRowInfo rowInfo = vInfo.RowsInfo[i] as GridDataRowInfo;
                if (rowInfo != null)
                {
                    GridCellInfo cInfo = rowInfo.Cells[0];//合并的列

                   //如果是合并的,就认为同一行,

                    if (cInfo.IsMerged)
                    {
                        if (!cInfo.CellValue.Equals(lastValue))
                            j++;
                        lastValue = cInfo.CellValue;
                    }
                    else
                    {
                        j++;
                    }
                    if (j % 2 == 0)
                    {
                        evenRowHandle.Add(cInfo.RowHandle);//根据自己定义的行号判断是否偶数行
                    }
                }
            }
            return evenRowHandle;
        }

得到需要设置的Rowhandle后,就在RowCellStyle事件设置对应Rowhandle的BackColor了。


标签:GridControl  BandedGridView  合并单元格  隔行换色 

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。本文出自“wpf之家”,请务必保留此出处:http://www.wpf123.com

相关评论
Copyright © 2009-2014 WPF之家(http://www.wpf123.com/) All rights reserved
 Powered by WPF之家
闽ICP备10004896号