The hierarchical display of the datagridview. If you want to find a third-party control, you can enter the datagridview outlook in the codeproject. There is a control that looks good. The following code simply achieves this effect and does not feel necessary to rewrite the control.
You can see the truth in a picture first.
Okay, this function will be available at a Glance. The code below will be provided (the data source binding will be omitted, and the idea will be OK, huh, huh)
Code
# Region draw Cells
Private void dgvalarmlog_rowpostpaint (Object sender, datagridviewrowpostpainteventargs E)
{
If (E. rowindex> = 0)
{
Graphics G = E. graphics;
If (dgvalarmlog. rows [E. rowindex]. cells [0]. value = plusimage | dgvalarmlog. rows [E. rowindex]. cells [0]. value = subimage)
{
Using (Brush gridbrush = new solidbrush (this. dgvalarmlog. gridcolor), backcolorbrush = new solidbrush (color. White), fontbrush = new solidbrush (system. Drawing. color. Black ))
{
// Offline
Rectangle rect = E. rowbounds;
G. fillrectangle (backcolorbrush, rect. x + 30, rect. Y, dgvalarmlog. Width, rect. Height-1 );
// Define the font
Font font = new font ("", 10, fontstyle. Bold );
String STR = dgvalarmlog. Rows [E. rowindex]. cells [3]. value. tostring ();
// Display date
G. drawstring (STR, Font, fontbrush, rect. x + 50, rect. Y + 4 );
}
}
}
}
# Endregion
# Region display sub-Data
Private void dgvalarmlog_cellcontentclick (Object sender, datagridviewcelleventargs E)
{
// Click the image
If (E. columnindex = 0 & E. rowindex> = 0)
{
Object imagevalue = dgvalarmlog. Rows [E. rowindex]. cells [0]. value;
If (imagevalue = plusimage) // expand
{
String [] STRs = (dgvalarmlog. Rows [E. rowindex]. cells [4]. value. tostring (). Split ('~ ');
String sdate = STRs [0]. Trim (); // start time
String edate = STRs [1]. Trim (); // End Time
Dgvalarmlog. Rows [E. rowindex]. cells [0]. value = subimage;
Datarow [] DRS = DT. Select ("happen_date> = '" + sdate + "' and happen_date <= '" + edate + "'");
Int COUNT = 0;
Foreach (datarow DR in DRS)
{
Dgvalarmlog. rows. insert (E. rowindex + 1 + (count ++), new object [] {blankimage, Dr ["describe"]. tostring (), Dr ["serial_no"]. tostring (), Dr ["happen_date"]. tostring (), Dr ["value"]. tostring (), Dr ["pre_value"]. tostring (), Dr ["avg_value"]. tostring ()});
}
}
Else if (imagevalue = subimage) // fold
{
Dgvalarmlog. Rows [E. rowindex]. cells [0]. value = plusimage;
Try
{
Object tempimage = dgvalarmlog. Rows [E. rowindex + 1]. cells [0]. value;
While (tempimage! = Plusimage & tempimage! = Subimage)
{
Dgvalarmlog. Rows. removeat (E. rowindex + 1 );
Tempimage = dgvalarmlog. Rows [E. rowindex + 1]. cells [0]. value;
}
}
Catch {}
}
}
}
# Endregion
Let's look at a second-level directory: