zoukankan
html css js c++ java
Datagrid中隐藏、合并相同文字列
/**/
///
<summary>
///
方法编号:06
///
方法名称:CombineRepeatedCell
///
内容摘要:文字相同的列的合并
///
算法思路:将相同的连续单元格想象成“块”,将"块"放置在数据容器中,全部遍历相加需合并的单元格的rowspan,来进行合并隐藏的动作
///
</summary>
///
<param name="m_arrIndex">
需要合并的列的index数据
</param>
public
void
CombineRepeatedCell(DataGrid m_grid,
int
[] m_arrIndex)
{
foreach
(
int
m_colIndex
in
m_arrIndex)
//
列
{
ArrayList m_hidCells
=
new
ArrayList();
//
得到需合并的item
for
(
int
i
=
0
; i
<
m_grid.Items.Count; i
++
)
{
//
第一行不用比较,并终止比较于最后一行
if
(i
==
0
||
i
==
(m_grid.PageSize
*
m_grid.CurrentPageIndex))
{
m_hidCells.Add(m_grid.Items[i].Cells[m_colIndex]);
continue
;
}
//
文字相同时
if
(
string
.Compare(m_grid.Items[i].Cells[m_colIndex].Text,m_grid.Items[i
-
1
].Cells[m_colIndex].Text)
==
0
)
{
m_hidCells.Add(m_grid.Items[i].Cells[m_colIndex]);
}
//
文字不同,或文字相同但已到最后一行
if
(m_grid.Items[i].Cells[m_colIndex].Text
!=
m_grid.Items[i
-
1
].Cells[m_colIndex].Text
||
i
==
m_grid.Items.Count
-
1
)
{
//
一旦发现有不同的文字,即表示单元格块的结束
if
(m_hidCells.Count
<=
0
)
//
无需合并
{
return
;
}
int
m_iRowspan
=
0
;
//
待合并的单元格的Rowspan
foreach
(TableCell c
in
m_hidCells)
{
m_iRowspan
+=
(c.RowSpan
>
0
)
?
c.RowSpan :
1
;
}
for
(
int
ii
=
1
; ii
<=
m_hidCells.Count
-
1
; ii
++
)
{
((TableCell)m_hidCells[ii]).Visible
=
false
;
}
((TableCell)m_hidCells[
0
]).RowSpan
=
m_iRowspan;
//
开始制作新的容器
m_hidCells
=
new
ArrayList();
m_hidCells.Add(m_grid.Items[i].Cells[m_colIndex]);
continue
;
}
//
for 结束
}
//
foreach 结束
}
//
foreach (int i in m_arrIndex) 结束
}
//
CombineRepeatedCell 结束
/**/
///
<summary>
///
方法编号:03
///
方法名称:HideRepeatedCell
///
内容摘要:文字相同的列的隐藏
///
算法思路:不能在循环ITEM的时候进行合并或隐藏,以免比较出现错误
///
只能暂先放置在容器中,全部遍历方进行合并隐藏的动作
///
</summary>
///
<param name="m_grid"></param>
///
<param name="m_arrIndex">
需要隐藏的列的index数据
</param>
public
void
HideRepeatedCell(DataGrid m_grid,
int
[] m_arrIndex)
{
if
(m_arrIndex.Length
<=
0
)
//
检查特异情况
{
return
;
}
//
处理重复时隐藏
ArrayList m_hidCells
=
new
ArrayList();
//
得到需隐藏的item
foreach
(DataGridItem item
in
m_grid.Items)
{
if
(item.ItemType
==
ListItemType.Item
||
item.ItemType
==
ListItemType.AlternatingItem)
{
//
如果为第一行,且跳过
if
(item.ItemIndex
==
0
||
item.ItemIndex
==
(m_grid.PageSize
*
m_grid.CurrentPageIndex))
{
continue
;
}
foreach
(
int
m_colIndex
in
m_arrIndex)
{
if
(item.Cells[m_colIndex].Text
==
m_grid.Items[item.ItemIndex
-
1
].Cells[m_colIndex].Text)
{
m_hidCells.Add(item.Cells[m_colIndex]);
}
else
{
break
;
}
}
}
//
if (item.ItemType == ListItemType.Item
结束
}
//
foreach (DataGridItem item in m_grid.Items) 结束
//
开始隐藏
foreach
(
object
obj
in
m_hidCells)
{
((TableCell)obj).Text
=
string
.Empty;
}
}
//
HideRepeatedCell 结束
愿一路奔跑不退缩,到目前一直从事.Net的B/S,C/S企业应用研发
查看全文
相关阅读:
理解Restful 架构
CLR 异步函数
CLR 线程池
CLR 线程基础
CLR 序列化
CLR 垃圾回收和应用程序集
CLR的垃圾回收机制
定制特性
枚举和迭代器
接口
原文地址:https://www.cnblogs.com/syveen/p/231763.html
最新文章
物体运动学习笔记(二)
第1章 概述
第10章 图形用户界面设计
第5章 继承、接口和泛型
第4章 类和对象
第3章 运算符、表达式和语句
第1章 概述
一维随机变量及其分布
随机事件及其概率
设备管理
热门文章
Ubuntu ChromeDriver的安装
Ubuntu20.0.4 安装chrome浏览器
Ubuntn 下搭建python人工智能环境
Sevlet reouestDisaatcher:的forward()kinclude的区别
Windows 下安装Linux Ubuntu
JavaC组蓝桥杯 107道历年真题
Eclipse 解放鼠标的快捷键
JavaWeb笔记——第四章HTTP协议
Java 递归、DFS、剪枝、回溯例题
Python DLib库进行人脸关键点识别
Copyright © 2011-2022 走看看