/**//// <summary> /// DataGrid中相同单元格的合并 /// </summary> public void SpanGrid() ...{ int i; int j; int intSpan; string strTemp; for (i = 0; i < DataGrid1.Items.Count;) ...{ intSpan = 1; strTemp = DataGrid1.Items[i].Cells[0].Text; //循环判断,判断第一列中,和第一行相同的内容 for (j = i + 1; j < DataGrid1.Items.Count; j ++) ...{ if (string.Compare(strTemp, DataGrid1.Items[j].Cells[1].Text) == 0) ...{ intSpan += 1; //利用datagrid的RowSpan属性 DataGrid1.Items[i].Cells[0].RowSpan = intSpan; //把内容相同单元格隐藏 DataGrid1.Items[j].Cells[0].Visible = false; } else ...{ break; } } i = j -1; } }