您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“C#如何實(shí)現(xiàn)DataGrid列格式”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“C#如何實(shí)現(xiàn)DataGrid列格式”這篇文章吧。
寫winForm的程序,難免要用DataGrid,自然也就需要設(shè)置C# DataGrid列格式,標(biāo)題之類的!但是經(jīng)常列標(biāo)題設(shè)置后沒反應(yīng),好惡心!這幾天做了個(gè)程序,自己研究了一下,主要有有一個(gè)地方要注意!
C# DataGrid列格式代碼不需要在控件上做任何設(shè)置,照著寫就能搞定!
private void frmLog_Load(object sender, System.EventArgs e){ //設(shè)置DataGrid的列寬 InitDataGridColumnHeader(); //GetResult(); } private void InitDataGridColumnHeader(){ DataGridTableStyle dts=new DataGridTableStyle(); //注意:必須加上這一句,否則自定義列格式無法使用 dts.MappingName="Table"; hrgLog.TableStyles.Add(dts); hrgLog.TableStyles[0].GridColumnStyles.Clear(); DataGridTableStyle dtsLog = new DataGridTableStyle(); DataGridTextBoxColumn colID = new DataGridTextBoxColumn(); colID.Width=80; colID.HeaderText = "記錄序號(hào)"; colID.MappingName = "ID"; hrgLog.TableStyles[0].GridColumnStyles.Add(colID); DataGridTextBoxColumn colLog = new DataGridTextBoxColumn(); colLog.Width=200; colLog.HeaderText = "日志內(nèi)容"; colLog.MappingName = "LogMessage"; hrgLog.TableStyles[0].GridColumnStyles.Add(colLog); DataGridTextBoxColumn colTime = new DataGridTextBoxColumn(); colTime.Width=100; colTime.HeaderText = "記錄時(shí)間"; colTime.MappingName = "LogTime"; hrgLog.TableStyles[0].GridColumnStyles.Add(colTime); DataGridTextBoxColumn colCatalog = new DataGridTextBoxColumn(); colCatalog.Width=100; colCatalog.HeaderText = "日志類別"; colCatalog.MappingName = "LogCatalog"; hrgLog.TableStyles[0].GridColumnStyles.Add(colCatalog); }
以上是“C#如何實(shí)現(xiàn)DataGrid列格式”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。