偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

老鳥談ADO.NET DataGridView控件屬性

開發(fā) 后端
這里就ADO.NET DataGridView控件屬性AllowUserToAddRows 獲取或設置一個值,該值指示是否向用戶顯示添加行的選項,文章還有更多的屬性介紹。

我們大家都知道ADO.NET訪問數(shù)據(jù)庫技術,上網(wǎng)也收集里許多資料,在這里就ADO.NET DataGridView控件屬性給大家講述一番,大家都知道隨著一個技術的發(fā)展,它的各個功能也都隨著完善,在ADO.NET2.0提供一種強大而靈活的以表格形式顯示數(shù)據(jù)的方式。

#T#使用DataGridView控件來顯示少量數(shù)據(jù)的只讀視圖,也可以對其進行縮放以顯示特大數(shù)據(jù)集的可編輯視圖。可以用很多方式擴展DataGridView控件,以便將自定義行為內(nèi)置在應用程序中。例如,可以采用編程方式指定自己的排序算法,以及創(chuàng)建自己的單元格類型。通過選擇一些屬性,可以輕松地自定義ADO.NET DataGridView控件屬性的外觀??梢詫⒃S多類型的數(shù)據(jù)存儲區(qū)用作數(shù)據(jù)源,也可以在沒有綁定數(shù)據(jù)源的情況下操作DataGridView控件。

常用的ADO.NET DataGridView控件屬性請參見表所示:

 

屬性
說明
AllowUserToAddRows
獲取或設置一個值,該值指示是否向用戶顯示添加行的選項。
AllowUserToDeleteRows
獲取或設置一個值,該值指示是否允許用戶從DataGridView中刪除行。
AllowUserToOrderColumns
獲取或設置一個值,該值指示是否允許通過手動對列重新定位。
AllowUserToResizeColumns
獲取或設置一個值,該值指示用戶是否可以調(diào)整列的大小。
AllowUserToResizeRows
獲取或設置一個值,該值指示用戶是否可以調(diào)整行的大小。
DataSource
獲取或設置DataGridView所顯示數(shù)據(jù)的數(shù)據(jù)源
Columns
獲取一個包含控件中所有列的集合。

詳細代碼:

  1. privatevoidInitializeDataGridView()  
  2. {  
  3. try  
  4. {  
  5. //建立DataGridView控件  
  6. dataGridView1.Dock=DockStyle.Fill;  
  7. //自動生成DataGridView列  
  8. dataGridView1.AutoGenerateColumns=true;  
  9. //建立數(shù)據(jù)源  
  10. bindingSource1.DataSource=GetData("Select*FromProducts");  
  11. dataGridView1.DataSource=bindingSource1;  
  12. //自動調(diào)整可視化行  
  13. dataGridView1.AutoSizeRowsMode=DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;  
  14. //設置DataGridView控件的邊界  
  15. dataGridView1.BorderStyle=BorderStyle.Fixed3D;  
  16. //當用戶使用DataGridView控件時,它會成為可編輯模式  
  17. dataGridView1.EditMode=DataGridViewEditMode.EditOnEnter;  
  18. }  
  19. catch(SqlExceptione)  
  20. {  
  21. MessageBox.Show("Torunthissamplereplaceconnection.ConnectionString"+"withavalidconnectionstringtoaNorthwind"+"databaseaccessibletoyoursystem.","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);  
  22. System.Threading.Thread.CurrentThread.Abort();  
  23. }  
  24. }  
  25. privatestaticDataTableGetData(stringsqlCommand)  
  26. {  
  27. stringconnectionString="IntegratedSecurity=SSPI;"+"PersistSecurityInfo=False;"+"InitialCatalog=Northwind;DataSource=localhost";  
  28. SqlConnectionnorthwindConnection=newSqlConnection(connectionString);  
  29. SqlCommandcommand=newSqlCommand(sqlCommand,northwindConnection);  
  30. SqlDataAdapteradapter=newSqlDataAdapter();  
  31. adapter.SelectCommand=command;  
  32. DataTabletable=newDataTable();  
  33. table.Locale=System.Globalization.CultureInfo.InvariantCulture;  
  34. adapter.Fill(table);  
  35. returntable;  


代碼中dataGridView1.DataSource被設置為bindingSource1。

責任編輯:田樹 來源: 博客
相關推薦

2009-11-04 13:20:28

ADO.NET Dat

2009-11-04 13:08:29

ADO.NET Dat

2009-11-12 15:12:57

ADO.NET實體框架

2009-12-22 16:35:11

ADO.NET控件

2009-11-04 11:30:35

ADO.NET Dat

2009-12-21 14:55:49

ADO.NET屬性

2009-12-30 15:11:35

ADO.NET數(shù)據(jù)

2009-12-22 13:49:40

ADO.net屬性

2009-11-11 09:48:08

ADO.NET Com

2009-12-28 15:11:36

ADO.NET專家

2009-12-30 16:58:43

ADO.NET

2009-11-03 16:37:10

2011-05-20 11:31:07

ADO.NET

2009-11-12 13:19:55

2009-12-18 15:19:50

2009-09-14 13:37:25

LINQ ADO.NE

2009-12-23 09:26:56

ADO.NET屬性

2010-01-04 10:48:30

ADO.NET特色

2009-11-11 09:54:34

ADO.NET Rec

2009-11-03 17:25:59

ADO.NET編程技巧
點贊
收藏

51CTO技術棧公眾號