zoukankan
html css js c++ java
DataGrid行单元格合并显示 (增加交错行颜色设置)
//
绑定数据集
public
void
BindGrid()
{
DataSet ds
=
new
DataSet();
sqlDataAdapter2.Fill(ds);
DataGrid2.DataSource
=
ds.Tables[
0
];
DataGrid2.DataBind();
//
合并相同的单元格
string
strTemp;
int
intSpan
=
0
;
int
nowSpan
=
0
;
bool
flag
=
false
;
int
i, j;
for
(i
=
0
; i
<
DataGrid2.Items.Count; i
++
)
{
intSpan
=
1
;
strTemp
=
DataGrid2.Items[i].Cells[
0
].Text;
if
(flag
==
true
)
{
flag
=
false
;
DataGrid2.Items[i].BackColor
=
Color.SkyBlue;
for
(j
=
i
+
1
; j
<
DataGrid2.Items.Count; j
++
)
{
if
(String.Compare(strTemp,DataGrid2.Items[j].Cells[
0
].Text)
==
0
)
{
intSpan
=
intSpan
+
1
;
DataGrid2.Items[i].Cells[
0
].RowSpan
=
intSpan;
//
DataGrid2.Items[i].Cells[1].RowSpan = intSpan;
//
DataGrid2.Items[i].Cells[2].RowSpan = intSpan;
DataGrid2.Items[i].Cells[
3
].RowSpan
=
intSpan;
DataGrid2.Items[j].BackColor
=
Color.SkyBlue;
DataGrid2.Items[j].Cells[
0
].Visible
=
false
;
//
DataGrid2.Items[j].Cells[1].Visible = false;
//
DataGrid2.Items[j].Cells[2].Visible = false;
DataGrid2.Items[j].Cells[
3
].Visible
=
false
;
}
}
}
else
{
DataGrid2.Items[i].BackColor
=
Color.White;
flag
=
true
;
for
(j
=
i
+
1
; j
<
DataGrid2.Items.Count; j
++
)
{
if
(String.Compare(strTemp,DataGrid2.Items[j].Cells[
0
].Text)
==
0
)
{
intSpan
=
intSpan
+
1
;
DataGrid2.Items[i].Cells[
0
].RowSpan
=
intSpan;
//
DataGrid2.Items[i].Cells[1].RowSpan = intSpan;
//
DataGrid2.Items[i].Cells[2].RowSpan = intSpan;
DataGrid2.Items[i].Cells[
3
].RowSpan
=
intSpan;
DataGrid2.Items[j].BackColor
=
Color.White;
DataGrid2.Items[j].Cells[
0
].Visible
=
false
;
//
DataGrid2.Items[j].Cells[1].Visible = false;
//
DataGrid2.Items[j].Cells[2].Visible = false;
DataGrid2.Items[j].Cells[
3
].Visible
=
false
;
}
}
}
nowSpan
+=
intSpan;
i
=
nowSpan
-
1
;
}
}
查看全文
相关阅读:
VS2010 MFC对话框程序用CButtonST给按钮添加图标
VS2010 MFC 使用GDI+给图片添加汉字
C++ Primer(第4版)-学习笔记-第2部分:容器和算法
C++ 面向对象编程
C++类(Class)总结
delegate、notification、KVO场景差别
iOS block种类和切换
Copy 与MutableCopy的区别
ios 避免循环引用
WKInterfaceImage 无法更新图片的问题
原文地址:https://www.cnblogs.com/adam/p/1023368.html
最新文章
[crash详解与防护] NSNotification crash
[crash详解与防护] NSTimer crash
[crash详解与防护] unrecognized selector crash
包管理工具Carthage使用
Push:iOS基于APNS的消息推送
Method Swizzling
【javascript】2017-9-12 腾讯笔试小Q升序算法
【javascript】操作给定的二叉树,将其变换为源二叉树的镜像。
利用栈对表达式求值
【js】js导出表格到excel
热门文章
【js数据结构】可逐次添加叶子的二叉树(非最优二叉树)
【js数据结构】图的深度优先搜索与广度优先搜索
【数据结构】树与二叉树
【js数据结构】栈解决佩兹糖果盒问题
AJAX初尝试——ACM/ICPC类比赛气球管理系统
POJ 1321 棋盘问题
SGU 223 Little Kings
SGU 222 Little Rooks
PHP 用 ZipArchive 打包指定文件到zip供用户下载
关于ACM,关于CSU
Copyright © 2011-2022 走看看