通过c1FlexGrid4.Styles.Add添加一个样式然后设置给这些单元格即可,要清除的时候,Remove这个样式就行,参考下面的代码
当然,你可以自己加个bool类型的变量判断,是否是选择区域的操作,,我这里的代码仅供参考
- private void C1FlexGrid4_MouseClick(object sender, MouseEventArgs e)
- {
- var hitinfo = c1FlexGrid4.HitTest();
- if (hitinfo.Type== HitTestTypeEnum.Cell)
- {
- if(c1FlexGrid4.Tag==null)
- {
- c1FlexGrid4.Tag = new Point(hitinfo.Column, hitinfo.Row) ;
- if(c1FlexGrid4.Styles["SelectStyle"]!=null)
- c1FlexGrid4.Styles.Remove("SelectStyle");
- }
- else
- {
- c1FlexGrid4.Styles.Add("SelectStyle");
- c1FlexGrid4.Styles["SelectStyle"].BackColor= Color.LightSeaGreen;
- Point point1 = (Point)c1FlexGrid4.Tag;
- for (int row = point1.Y + 1; row < hitinfo.Row; row++)
- {
- c1FlexGrid4.Rows[row].Style= c1FlexGrid4.Styles["SelectStyle"];
- }
- var toprowrange = c1FlexGrid4.GetCellRange(point1.Y, point1.X, point1.Y, c1FlexGrid4.Cols.Count-1);
- toprowrange.Style= c1FlexGrid4.Styles["SelectStyle"];
- var bottomrange = c1FlexGrid4.GetCellRange(hitinfo.Row, 0, hitinfo.Row, hitinfo.Column);
- bottomrange.Style = c1FlexGrid4.Styles["SelectStyle"];
- c1FlexGrid4.Tag = null;
- }
- }
- }
复制代码 |