In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces what is the use of the DataGridView control in ADO.NET, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Use the DataGridView control to display a read-only view of a small amount of data, or you can zoom to display an editable view of an extra large dataset. You can extend the DataGridView control in many ways to build custom behavior into your application. For example, you can programmatically specify your own sorting algorithm and create your own cell types. You can easily customize the appearance of the ADO.NET DataGridView control properties by selecting some properties. You can use many types of datastores as data sources, or you can manipulate DataGridView controls without binding the data source.
For commonly used ADO.NET DataGridView control properties, see the table:
Attribute
Description
AllowUserToAddRows
Gets or sets a value indicating whether the option to add rows is displayed to the user.
AllowUserToDeleteRows
Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
AllowUserToOrderColumns
Gets or sets a value indicating whether column repositioning is allowed manually.
AllowUserToResizeColumns
Gets or sets a value indicating whether the user can resize the column.
AllowUserToResizeRows
Gets or sets a value indicating whether the user can resize the row.
DataSource
Gets or sets the data source for the data displayed by DataGridView
Columns
Gets a collection containing all the columns in the control.
Detailed code:
PrivatevoidInitializeDataGridView () {try {/ / establish DataGridView control dataGridView1.Dock=DockStyle.Fill; / / automatically generate DataGridView column dataGridView1.AutoGenerateColumns=true; / / create data source bindingSource1.DataSource=GetData ("Select*FromProducts"); dataGridView1.DataSource=bindingSource1; / / automatically adjust visual row dataGridView1.AutoSizeRowsMode=DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders; / / set the boundary dataGridView1.BorderStyle=BorderStyle.Fixed3D; of the DataGridView control / / when the user uses the DataGridView control, it becomes the editable mode dataGridView1.EditMode=DataGridViewEditMode.EditOnEnter } catch (SqlExceptione) {MessageBox.Show ("Torunthissamplereplaceconnection.ConnectionString" + "withavalidconnectionstringtoaNorthwind" + "databaseaccessibletoyoursystem.", "ERROR", MessageBoxButtons.OK,MessageBoxIcon.Exclamation); System.Threading.Thread.CurrentThread.Abort ();} privatestaticDataTableGetData (stringsqlCommand) {stringconnectionString= "IntegratedSecurity=SSPI;" + "PersistSecurityInfo=False;" + "InitialCatalog=Northwind;DataSource=localhost"; SqlConnectionnorthwindConnection=newSqlConnection (connectionString); SqlCommandcommand=newSqlCommand (sqlCommand,northwindConnection); SqlDataAdapteradapter=newSqlDataAdapter (); adapter.SelectCommand=command; DataTabletable=newDataTable (); table.Locale=System.Globalization.CultureInfo.InvariantCulture; adapter.Fill (table) Returntable;}
DataGridView1.DataSource is set to bindingSource1 in the code.
Thank you for reading this article carefully. I hope the article "what is the use of DataGridView controls in ADO.NET" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.