/// <Summary>
/// Vertically merge the same text cells in the specified Column
/// </Summary>
/// <Usage>
/// Mergesamecellattextcolumn (datagridinstance, columnindex );
/// </Usage>
/// <Param name = "curgrid"> </param>
/// <Param name = "columnindex"> </param>
Private void mergesamecellattextcolumn (DataGrid curgrid, int columnindex)
{
Datagriditem curitem = NULL;
Datagriditem nextitem = NULL;
For (INT r = 0; r <curgrid. Items. Count; r ++)
{
/// Current cell
Curitem = curgrid. items [R];
/// Cell under it
If (R + 1 <curgrid. Items. Count)
Nextitem = curgrid. items [R + 1];
Else
Nextitem = NULL;
String curvalue = curitem = NULL? String. Empty: curitem. cells [columnindex]. text;
String nextvalue = nextitem = NULL? String. Empty: nextitem. cells [columnindex]. text;
/// If the cell content is the same
If (curvalue! = String. Empty & nextvalue! = String. Empty & curvalue = nextvalue)
{
/// Set the cells under it to invisible
If (nextvalue! = NULL) nextitem. cells [columnindex]. Visible = false;
/// If the current cell is visible, set its rowspan + 1
If (curitem. cells [columnindex]. Visible = true)
{
Curitem. cells [columnindex]. rowspan + = 1;
}
/// If the current cell is invisible, it is directly traced back to its first visible cell.
Else if (curitem. cells [columnindex]. Visible = false)
{
Int prerowindex = R;
While (prerowindex> = 0 & curgrid. items [prerowindex]. cells [columnindex]. Visible = false)
{
Prerowindex-= 1;
}
/// Set rowspan + 1 of the first visible cell
Curgrid. items [prerowindex]. cells [columnindex]. rowspan + = 1;
}
}
/// If the cell content is different
Else if (curvalue! = String. Empty & nextvalue! = String. Empty & curvalue! = Nextvalue)
{
/// Determine whether the row is a critical row: The preceding row or multiple rows have different content from the corresponding cells of the following row or multiple rows.
If (curitem. cells [columnindex]. Visible = false)
{
Int prerowindex = R;
While (prerowindex> = 0 & curgrid. items [prerowindex]. cells [columnindex]. Visible = false)
{
Prerowindex-= 1;
}
/// Set rowspan + 1 of the first visible cell
Curgrid. items [prerowindex]. cells [columnindex]. rowspan + = 1;
}
Else
{
/// Non-critical
}
}
/// The last row of the Data list
Else if (r = curgrid. Items. Count-1 & curitem. cells [columnindex]. Visible = false)
{
Int prerowindex = R;
While (prerowindex> = 0 & curgrid. items [prerowindex]. cells [columnindex]. Visible = false)
{
Prerowindex-= 1;
}
/// Set rowspan + 1 of the first visible cell
Curgrid. items [prerowindex]. cells [columnindex]. rowspan + = 1;
}
}
}
/// <Summary>
/// Vertically merge the same template cell of the specified Column
/// </Summary>
/// <Usage>
/// Mergesamecellattemplatecolumn (maid, "templatecontrolid", columnindex );
/// </Usage>
/// <Param name = "curgrid"> </param>
/// <Param name = "columnindex"> </param>
/// <Param name = "controlname"> </param>
Private void mergesamecellattemplatecolumn (DataGrid curgrid, int columnindex, string controlname)
{
Datagriditem curitem = NULL;
Datagriditem nextitem = NULL;
For (INT r = 0; r <curgrid. Items. Count; r ++)
{
/// Current cell
Curitem = curgrid. items [R];
/// Cell under it
If (R + 1 <curgrid. Items. Count)
Nextitem = curgrid. items [R + 1];
Else
Nextitem = NULL;
/// When calling, pay attention to modifying the template control type and the method for obtaining the template control value.
String curvalue = curitem = NULL? String. Empty :( (ListBox) curitem. findcontrol (controlname). selectedtext;
String nextvalue = nextitem = NULL? String. Empty :( (ListBox) nextitem. findcontrol (controlname). selectedtext;
/// If the cell content is the same
If (curvalue! = String. Empty & nextvalue! = String. Empty & curvalue = nextvalue)
{
/// Set the cells under it to invisible
If (nextvalue! = NULL) nextitem. cells [columnindex]. Visible = false;
/// If the current cell is visible, set its rowspan + 1
If (curitem. cells [columnindex]. Visible = true)
{
Curitem. cells [columnindex]. rowspan + = 1;
}
/// If the current cell is invisible, it is directly traced back to its first visible cell.
Else if (curitem. cells [columnindex]. Visible = false)
{
Int prerowindex = R;
While (prerowindex> = 0 & curgrid. items [prerowindex]. cells [columnindex]. Visible = false)
{
Prerowindex-= 1;
}
/// Set rowspan + 1 of the first visible cell
Curgrid. items [prerowindex]. cells [columnindex]. rowspan + = 1;
}
}
/// If the cell content is different
Else if (curvalue! = String. Empty & nextvalue! = String. Empty & curvalue! = Nextvalue)
{
/// Determine whether the row is a critical row: The preceding row or multiple rows have different content from the corresponding cells of the following row or multiple rows.
If (curitem. cells [columnindex]. Visible = false)
{
Int prerowindex = R;
While (prerowindex> = 0 & curgrid. items [prerowindex]. cells [columnindex]. Visible = false)
{
Prerowindex-= 1;
}
/// Set rowspan + 1 of the first visible cell
Curgrid. items [prerowindex]. cells [columnindex]. rowspan + = 1;
}
Else
{
/// Non-critical
}
}
/// The last row of the Data list
Else if (r = curgrid. Items. Count-1 & curitem. cells [columnindex]. Visible = false)
{
Int prerowindex = R;
While (prerowindex> = 0 & curgrid. items [prerowindex]. cells [columnindex]. Visible = false)
{
Prerowindex-= 1;
}
/// Set rowspan + 1 of the first visible cell
Curgrid. items [prerowindex]. cells [columnindex]. rowspan + = 1;
}
}
}