# Region formatdg
Private void formatgrid (DataGrid DG, int T)
{
If (DG. Items. Count! = 0)
{
Int begin = 0; // merge the same customer names. Begin is the first column.
Int end = 0; // end is the end column.
String pre = DG. items [0]. cells [T]. Text; // mark, indicating the first column with the same customer name
String cur; // the name of the next customer
For (INT I = 0; I <DG. Items. Count; I ++)
{
Cur = DG. items [I]. cells [T]. text;
If (cur! = Pre) // if the names of the first and second customers are different
{
End = I-1;
Pre = cur; // pre becomes the new customer name
If (end> begin)
{
For (Int J = begin + 1; j <= end; j ++) // clears the same customer name from begin to end.
{
DG. items [begin]. cells [T]. rowspan = end-begin + 1;
DG. items [J]. cells [T]. Visible = false;
// DG. items [J]. cells. removeat (0 );
}
}
Else // the last group of customers
{
End = DG. Items. count;
For (Int J = begin + 1; j <end; j ++)
{
DG. items [begin]. cells [T]. rowspan = end-begin;
DG. items [J]. cells [T]. Visible = false;
// DG. items [J]. cells. removeat (0 );
}
}
Begin = I;
}
Else // only has one group of identical Customer names
{
End = DG. Items. count;
If (I = DG. Items. Count-1)
{
For (Int J = begin + 1; j <end; j ++)
{
DG. items [begin]. cells [T]. rowspan = end-begin;
DG. items [J]. cells [T]. Visible = false;
// DG. items [J]. cells. removeat (0 );
}
}
}
}
}
}
# Endregion