日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【转】DataGridView新特色(vs2005)

發(fā)布時間:2024/9/5 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【转】DataGridView新特色(vs2005) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1、自定義列 Customize Cells and Columns in the Windows Forms DataGridView Control by Extending Their Behavior and Appearance Host Controls in Windows Forms DataGridView Cells 繼承 DataGridViewTextBoxCell 類生成新的Cell類,然后再繼承 DataGridViewColumn 生成新的Column類,并指定 CellTemplate為新的Cell類。新生成的Column便可以增加到DataGridView中去。 2、自動適應(yīng)列寬 ??? Programmatically Resize Cells to Fit Content in the Windows Forms DataGridView Control Samples: DataGridView.AutoSizeColumns( DataGridViewAutoSizeColumnCriteria.HeaderAndDisplayedRows); DataGridView.AutoSizeColumn( DataGridViewAutoSizeColumnCriteria.HeaderOnly, 2, false); DataGridView.AutoSizeRow( DataGridViewAutoSizeRowCriteria.Columns, 2, false); DataGridView.AutoSizeRows( DataGridViewAutoSizeRowCriteria.HeaderAndColumns, 0, dataGridView1.Rows.Count, false); 3、可以綁定并顯示對象 ??? Bind Objects to Windows Forms DataGridView Controls 4、可以改變表格線條風(fēng)格 ??? Change the Border and Gridline Styles in the Windows Forms DataGridView Control Samples: this.dataGridView1.GridColor = Color.BlueViolet; this.dataGridView1.BorderStyle = BorderStyle.Fixed3D; this.dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None; this.dataGridView1.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; this.dataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; 5、動態(tài)改變列是否顯示,和動態(tài)改變列的顯示順序 ??? Change the Order of the Columns in the Windows Forms DataGridView Control Samples: customersDataGridView.Columns["CustomerID"].Visible = false; customersDataGridView.Columns["ContactName"].DisplayIndex = 0; customersDataGridView.Columns["ContactTitle"].DisplayIndex = 1; customersDataGridView.Columns["City"].DisplayIndex = 2; customersDataGridView.Columns["Country"].DisplayIndex = 3; customersDataGridView.Columns["CompanyName"].DisplayIndex = 4; 6、可以在列中顯示圖像 ??? Display Images in Cells of the Windows Forms DataGridView Control Samples: Icon treeIcon = new Icon(this.GetType(), "tree.ico"); DataGridViewImageColumn iconColumn = new DataGridViewImageColumn (); iconColumn.Image = treeIcon.ToBitmap(); iconColumn.Name = "Tree"; iconColumn.HeaderText = "Nice tree"; dataGridView1.Columns.Insert(2, iconColumn); 7、格式化顯示內(nèi)容: ??? Format Data in the Windows Forms DataGridView Control Samples: this.dataGridView1.Columns["UnitPrice"].DefaultCellStyle.Format = "c"; this.dataGridView1.Columns["ShipDate"].DefaultCellStyle.Format = "d"; this.dataGridView1.DefaultCellStyle.NullValue = "no entry"; this.dataGridView1.DefaultCellStyle.WrapMode = DataGridViewWrapMode.Wrap; this.dataGridView1.Columns["CustomerName"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; 8、在拖動列的滾動條時可以將指定的列凍結(jié) ??? Freeze Columns in the Windows Forms DataGridView Control Samples:將指定列及以前的列固定不動 this.dataGridView1.Columns["AddToCartButton"].Frozen = true; 9、獲取選擇的單元格,行,列 ??? Get the Selected Cells, Rows, and Columns in the Windows Forms DataGridView Control Samples: 見msdn。 10、顯示錄入時出現(xiàn)的錯誤信息 ??? Handle Errors that Occur During Data Entry in the Windows Forms DataGridView Control Samples: private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e) { // If the data source raises an exception when a cell value is // commited, display an error message. if (e.Exception != null && e.Context == DataGridViewDataErrorContext.Commit) { MessageBox.Show("CustomerID value must be unique."); } } 11、大數(shù)據(jù)量顯示采用Virtual Mode Implement Virtual Mode in the Windows Forms DataGridView Control 12、設(shè)置指定的列只讀 ??? Make Columns in the Windows Forms DataGridView Control Read-Only Samples: dataGridView1.Columns["CompanyName"].ReadOnly = true; ? 13、移去自動生成的列 ??? Remove Autogenerated Columns from a Windows Forms DataGridView Control Sample: dataGridView1.AutoGenerateColumns = true; dataGridView1.DataSource = customerDataSet; dataGridView1.Columns.Remove ("Fax"); 或: dataGridView1.Columns["CustomerID"].Visible = false; 14、自定義選擇模式 ??? Set the Selection Mode of the Windows Forms DataGridView Control Sample: this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; this.dataGridView1.MultiSelect = false; 15、自定義設(shè)定光標(biāo)進入單元格是否編輯模式(編輯模式) Specify the Edit Mode for the Windows Forms DataGridView Control this.dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter; 16、新行指定默認(rèn)值 ??? Specify Default Values for New Rows in the Windows Forms DataGridView Control Sample: private void dataGridView1_DefaultValuesNeeded(object sender, ?????????????? ???????System.Windows.Forms.DataGridViewRowEventArgs e) { e.Row.Cells["Region"].Value = "WA"; e.Row.Cells["City"].Value = "Redmond"; e.Row.Cells["PostalCode"].Value = "98052-6399"; e.Row.Cells["Region"].Value = "NA"; e.Row.Cells["Country"].Value = "USA"; e.Row.Cells["CustomerID"].Value = NewCustomerId(); } 17、數(shù)據(jù)驗證 ??? Validate Data in the Windows Forms DataGridView Control Samples: private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { // Validate the CompanyName entry by disallowing empty strings. if (dataGridView1.Columns[e.ColumnIndex].Name == "CompanyName") { if (e.FormattedValue.ToString() == String.Empty) { dataGridView1.Rows[e.RowIndex].ErrorText = "Company Name must not be empty"; e.Cancel = true; } } }

轉(zhuǎn)載于:https://www.cnblogs.com/weck0736/archive/2008/01/14/1038142.html

與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的【转】DataGridView新特色(vs2005)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 成人国产亚洲 | 日本不卡高清视频 | 久久99精品久久久久久 | 国产精品欧美一区二区三区 | 亚洲午夜久久久久久久国产 | 久久精品导航 | 精品黄色av | 男人天堂综合网 | 欧美日在线 | 欧美图片自拍偷拍 | 美女被男人c | 国产三级免费观看 | 中文字幕一区二区三区久久久 | 久久精品视频91 | 欧美日韩一区二区三区免费 | 日韩精品久久久久久久的张开腿让 | 国产精品久久久久久中文字 | 麻豆激情网 | 欧美特一级片 | 狠狠视频| 久久久久99精品成人片直播 | 日韩久久不卡 | 天天摸天天操天天射 | 五十路黄色片 | 最新中文字幕第一页 | 中文字幕永久 | 国产日韩激情 | 一级在线播放 | 久久99综合 | 久久av无码精品人妻系列试探 | 国产视频黄色 | 日本人妖xxxx | 色男人影院 | 国产日韩欧美在线观看视频 | 无码人妻精品一区二区50 | 激情麻豆 | 视频二区欧美 | 日本a视频在线观看 | 成人三级在线播放 | 欧美色图激情小说 | 在线免费观看日本 | 天堂精品久久 | 久久久久久福利 | 亚洲男人天堂网站 | 樱花电影最新免费观看国语版 | 又紧又大又爽精品一区二区 | 午夜羞羞羞| 亚洲精品国产欧美在线观看 | 免费国产91 | 97无码精品人妻 | 久久精品这里只有精品 | 五月天综合激情网 | 日韩女优一区二区 | 9999精品视频 | 国产精品1024| 午夜理伦三级理论 | 一级欧美在线 | 夜夜夜操 | 日本动漫艳母 | 欧美视频一区二区三区四区在线观看 | 先锋av网| 国产人妖网站 | 五月婷婷七月丁香 | 国产视频福利在线观看 | 尤物视频在线看 | 牛牛av在线| 国产高清久久 | 国产伦理一区二区三区 | 色爱视频 | 99热99re6国产在线播放 | 亚洲精品v天堂中文字幕 | 欧美日韩精品一区 | 日婷婷 | 日韩视频a | 国产午夜三级 | 黄色片成年人 | 欧美一区二区三区大屁股撅起来 | 在线观看免费日韩av | 国产91丝袜在线观看 | 日韩久久久久久久久久久 | 99久久国产宗和精品1上映 | 日韩午夜在线播放 | 花房姑娘免费观看全集 | 99涩涩| 色爱视频 | 伊人国产一区 | 久久99热这里只频精品6学生 | 九九99精品 | 亚洲生活片 | 色偷偷免费| 青青草97 | 亚洲无人区码一码二码三码的含义 | 日本色网址| 久久九九免费 | 日本天堂在线视频 | 亚洲a精品 | 99久久99久久精品国产片桃花 | 两性av| 亚洲精品污一区二区三区 |