The DataGrid writes WinForm procedure, unavoidably must use the DataGrid, naturally also needs to set the column type Ah, the title and so on!
But often the list of headings does not respond, likes and dislikes!
These days to do a program, their own research, there is a major place to pay attention! That's " Red " in the code below.
Word part! The following code does not need to make any settings on the control, it can be done by writing! It used to be like someone paid 5000 cents.
The answer to this question, hey, how I did not meet Ah!
private void Frmlog_load (object sender, System.EventArgs e)
{
Set the column width of the datagrid
Initdatagridcolumnheader ();
GetResult ();
}
private void Initdatagridcolumnheader ()
{
DataGridTableStyle dts=new DataGridTableStyle ();
Note: You must add this sentence, otherwise the custom column format cannot be used
DTS. Mappingname= "Table";
HRGLOG.TABLESTYLES.ADD (dts);
Hrglog.tablestyles[0]. Gridcolumnstyles.clear ();
======================== Set Header field ===========================
DataGridTableStyle Dtslog = new DataGridTableStyle ();
DataGridTextBoxColumn ColID = new DataGridTextBoxColumn ();
colid.width=80;
Colid.headertext = "Record serial number";
Colid.mappingname = "ID";
Hrglog.tablestyles[0]. Gridcolumnstyles.add (ColID);
DataGridTextBoxColumn Collog = new DataGridTextBoxColumn ();
collog.width=200;
Collog.headertext = "Log Content";
Collog.mappingname = "LogMessage";
Hrglog.tablestyles[0]. Gridcolumnstyles.add (Collog);
DataGridTextBoxColumn coltime = new DataGridTextBoxColumn ();
coltime.width=100;
Coltime.headertext = "Record Time";
Coltime.mappingname = "LogTime";
Hrglog.tablestyles[0]. Gridcolumnstyles.add (Coltime);
DataGridTextBoxColumn Colcatalog = new DataGridTextBoxColumn ();
colcatalog.width=100;
Colcatalog.headertext = "Log category";
Colcatalog.mappingname = "Logcatalog";
Hrglog.tablestyles[0]. Gridcolumnstyles.add (Colcatalog);
}