1private void DataGrid_Join()
2 {
3 int iRow, iSpan=1, iRow_Start=0; //定义当前行数,合并行数,合并开始行标志
4 string sSText, sNText; //比较源文本,比较下一文本
5
6 for(iRow=0; iRow<DataGrid1.Items.Count-1; iRow++)
7 {
8 sSText = DataGrid1.Items[iRow].Cells[1].Text;
9 sNText = DataGrid1.Items[iRow+1].Cells[1].Text;
10 if(sSText == sNText)
11 {
12 DataGrid1.Items[iRow+1].Cells[2].Visible = false;
13 iSpan++;
14 }
15 else
16 {
17 iSpan = 1;
18 iRow_Start = iRow+1;
19 }
20 DataGrid1.Items[iRow_Start].Cells[2].RowSpan = iSpan;
21 }
22
23 //清除临时列
24 DataGrid1.Columns[1].Visible = false;
25 }
26
2 {
3 int iRow, iSpan=1, iRow_Start=0; //定义当前行数,合并行数,合并开始行标志
4 string sSText, sNText; //比较源文本,比较下一文本
5
6 for(iRow=0; iRow<DataGrid1.Items.Count-1; iRow++)
7 {
8 sSText = DataGrid1.Items[iRow].Cells[1].Text;
9 sNText = DataGrid1.Items[iRow+1].Cells[1].Text;
10 if(sSText == sNText)
11 {
12 DataGrid1.Items[iRow+1].Cells[2].Visible = false;
13 iSpan++;
14 }
15 else
16 {
17 iSpan = 1;
18 iRow_Start = iRow+1;
19 }
20 DataGrid1.Items[iRow_Start].Cells[2].RowSpan = iSpan;
21 }
22
23 //清除临时列
24 DataGrid1.Columns[1].Visible = false;
25 }
26