Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement DataGrid column format in C #

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report