The effect is shown in the "country" column in the first column. The same data can be merged into a cell for display.
My datagridview data source is bound to the database tutorial by dragging and dropping dataset on the graphical interface.
/// <Summary>
/// Merge rows with the same information in a column in the GridView (cell)
/// </Summary>
/// <Param name = "GridView1"> GridView </param>
/// <Param name = "cellNum"> column number </param>
Public static void GroupRows (GridView GridView1, int cellNum)
{
Int I = 0, rowSpanNum = 1;
While (I <GridView1.Rows. Count-1)
{
GridViewRow gvr = GridView1.Rows [I];
For (++ I; I <GridView1.Rows. Count; I ++)
{
GridViewRow gvrNext = GridView1.Rows [I];
If (gvr. Cells [cellNum]. Text = gvrNext. Cells [cellNum]. Text)
{
GvrNext. Cells [cellNum]. Visible = false;
RowSpanNum ++;
}
Else
{
Gvr. Cells [cellNum]. RowSpan = rowSpanNum;
RowSpanNum = 1;
Break;
}
If (I = GridView1.Rows. Count-1)
{
Gvr. Cells [cellNum]. RowSpan = rowSpanNum;
}
}
}
}