原創|其它|編輯:郝浩|2009-07-09 10:07:21.000|閱讀 540 次
概述:本文將介紹C#中對DatagridView的部分常用操作,包括自定義列、自動適應列寬、可以綁定并顯示對象等等。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
0(最基本的技巧)、獲取某列中的某行(某單元格)中的內容
this.currentposition = this.dataGridView1.BindingContext [this.dataGridView1.DataSource, this.dataGridView1.DataMember].Position; [this.currentposition][21].ToString().Trim(); |
1、自定義列
//定義列寬 |
繼承 DataGridViewTextBoxCell 類生成新的Cell類,然后再繼承 DataGridViewColumn 生成新的Column類,并指定
CellTemplate為新的Cell類。新生成的Column便可以增加到DataGridView中去。
2、自動適應列寬
Programmatically Resize Cells to Fit Content in the Windows Forms DataGridView Control |
3、可以綁定并顯示對象
Bind Objects to Windows Forms DataGridView Controls |
4、可以改變表格線條風格
Change the Border and Gridline Styles in the Windows Forms DataGridView Control |
5、動態改變列是否顯示,和動態改變列的顯示順序
Change the Order of the Columns in the Windows Forms DataGridView Control |
6、可以在列中顯示圖像
Display Images in Cells of the Windows Forms DataGridView Control |
7、格式化顯示內容:
Format Data in the Windows Forms DataGridView Control |
8、在拖動列的滾動條時可以將指定的列凍結
Freeze Columns in the Windows Forms DataGridView Control |
9、獲取選擇的單元格,行,列
Get the Selected Cells, Rows, and Columns in the Windows Forms DataGridView Control |
10、顯示錄入時出現的錯誤信息
Handle Errors that Occur During Data Entry in the Windows Forms DataGridView Control |
11、大數據量顯示采用Virtual Mode
Implement Virtual Mode in the Windows Forms DataGridView Control |
12、設置指定的列只讀
Make Columns in the Windows Forms DataGridView Control Read-Only |
13、移去自動生成的列
Remove Autogenerated Columns from a Windows Forms DataGridView Control |
14、自定義選擇模式
Set the Selection Mode of the Windows Forms DataGridView Control |
15、自定義設定光標進入單元格是否編輯模式(編輯模式)
Specify the Edit Mode for the Windows Forms DataGridView Control |
16、新行指定默認值
Specify Default Values for New Rows in the Windows Forms DataGridView Control (object sender, System.Windows.Forms.DataGridViewRowEventArgs e) |
17、數據驗證
Validate Data in the Windows Forms DataGridView Control |
18、數據提交到dataset中
DataSet ds = new DataSet("MyDataSet"); |
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:自互聯網