C# WinForm中DataGrid列设置(转载)
发布时间:2020-12-15 04:39:04 所属栏目:百科 来源:网络整理
导读:写winForm的程序,难免要用DataGrid,自然也就需要设置列格式啊,标题之类的!但是经常列标题设置后没反应,好恶心! p style="FONT-SIZE: 10pt" 这几天做了个程序,自己研究了一下,主要有有一个地方要注意!那就是下面代码中的“红色”字部分!以下代码不
写winForm的程序,难免要用DataGrid,自然也就需要设置列格式啊,标题之类的!但是经常列标题设置后没反应,好恶心! <div class="code" style="FONT-SIZE: 10pt"> <p style="FONT-SIZE: 10pt">private void frmLog_Load(object sender,System.EventArgs e)? {?? //设置DataGrid的列宽?? InitDataGridColumnHeader(); <p style="FONT-SIZE: 10pt">?? //GetResult();? } <p style="FONT-SIZE: 10pt">private void InitDataGridColumnHeader()? {?? DataGridTableStyle dts=new DataGridTableStyle(); <p style="FONT-SIZE: 10pt">?? //注意:必须加上这一句,否则自定义列格式无法使用?? dts.MappingName="Table"; <p style="FONT-SIZE: 10pt">?? hrgLog.TableStyles.Add(dts); <p style="FONT-SIZE: 10pt">?? hrgLog.TableStyles[0].GridColumnStyles.Clear(); <p style="FONT-SIZE: 10pt">?? //========================设置表头栏位===========================?? DataGridTableStyle dtsLog = new DataGridTableStyle();????? ?? DataGridTextBoxColumn colID = new DataGridTextBoxColumn();?? colID.Width=80; ?? colID.HeaderText = "记录序号";?? colID.MappingName = "ID"; <p style="FONT-SIZE: 10pt">?? hrgLog.TableStyles[0].GridColumnStyles.Add(colID);? ?? ?? DataGridTextBoxColumn colLog = new DataGridTextBoxColumn();?? colLog.Width=200; ?? colLog.HeaderText = "日志内容";?? colLog.MappingName = "LogMessage"; <p style="FONT-SIZE: 10pt">?? hrgLog.TableStyles[0].GridColumnStyles.Add(colLog);? ?? <p style="FONT-SIZE: 10pt">?? DataGridTextBoxColumn colTime = new DataGridTextBoxColumn();?? colTime.Width=100; ?? colTime.HeaderText = "记录时间";?? colTime.MappingName = "LogTime"; <p style="FONT-SIZE: 10pt">?? hrgLog.TableStyles[0].GridColumnStyles.Add(colTime);??? <p style="FONT-SIZE: 10pt">?? DataGridTextBoxColumn colCatalog = new DataGridTextBoxColumn();?? colCatalog.Width=100; ?? colCatalog.HeaderText = "日志类别";?? colCatalog.MappingName = "LogCatalog";? ?? hrgLog.TableStyles[0].GridColumnStyles.Add(colCatalog);???? ? } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 导致sqlite在执行时睡眠
- c# – StringLengthAttribute如何工作?
- 把DSP TMS320F28XXX的程序段从flash复制到ram中运行
- ruby – 如何在无头Chrome上使用Selenium Webdriver?
- ios – 如何让SKAction(名称:)可靠地运行?
- vb.net – 任何当前支持的Microsoft语言都可以创建Active X
- 通用权限管理组件支持SqLite,感谢完善者岩子(250952377)
- Cocos2d-JS项目之三:使用合图
- C++流程控制中用于跳转的return和goto语句学习教程
- 错误的PostgreSQL查询结果具有显式锁和并发事务