Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement DataGrid column format in C #

Shulou Source: shulou.com Published: 2022-06-02 09:16:07 10月30日 Update

This article mainly shows you "how to implement DataGrid column format in C#". The content is simple and easy to understand. The organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn "how to implement DataGrid column format in C#".

Write winForm program, inevitably use DataGrid, naturally also need to set C#DataGrid column format, title and the like! But often column title settings after no response, good nausea! These days to do a program, their own research, there is a place to pay attention to the main!

C#DataGrid column format code does not require any settings on the control, just write it!

private void frmLog_Load (object sender, System.EventArgs e){ //Set DataGrid column width InitDataGridColumnHeader (); //GetResult (); } private void InitDataGridColumnHeader (){ DataGridTableStyle dts=new DataGridTableStyle (); //Note: This sentence must be added, otherwise custom column formats cannot be used dts.MappingName="Table"; hrgLog.TableStyles.Add (dts); hrgLog.TableStyles[0]. ColumGridColumnStyles.Clear (); DataGridTableStyle dtsLog = new DataGridTableStyle (); DataGridTextBoxColumn colID = new DataGridTextBoxColumn (); colID.Width=80; colID.HeaderText = "Record 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 = "Recording 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); } Above is "C#How to implement DataGrid column format" All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Tags: Format clocking content article log title program study help research disgusting code place serial number control time easy to understand more organized follow Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Linux Redmi Apple macOS