How to generate our own serial number in gridview? Eg we have ten records in gridview so first col should represents serial no Like 1 2 3 to 10. Aug 24, 2013 How to Auto generate Serial number in GridView in Windows Application. Windows Forms. If you are binding a DataTable to the DataGridView, then you can add a new DataColumn with its AutoIncrement property set to true. DataColumn dcAuto = new DataColumn.
To make the datagride inquiry more speaking a serial number is very much needed but using the database serial number is not proper as database serial number is a serial number of whole data available in data table.where we generate inquiry on special parameter. And it is very simple to create a serial number in adatagride. for that we need to take following step :- Place a datagride on the window form and set the data source and data member as per your requirement
2. Right click on data grid viewer and click on edit column
after clicking on edit columns then click on Add button then you will get another form on that form select radio button uncontrol column and fill name of the column as 'clmsno' and Header which will be shown in your data grid viewer 'S.NO' and tick the check box 'visible' and 'read only.:
3. After doing that move the S.No from bottom to top or where you want to show by clicking on up and down arrow.
4. then change the virtual mode property of data grid viewer as true.
5.then write following code on Cellvalueneeded event of data grid
Private Sub DataGridView1_CellValueNeeded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValueEventArgs) Handles DataGridView1.CellValueNeeded
If e.RowIndex >= 0 AndAlso e.ColumnIndex = Me.sno.Index Then
End If
then run the programme and you will get an auto generated serial number in your inquiry serial
To understand Vb.Net in better way I will suggest you to have book written by Anne Prince 'Murach Visual Basic' and that is available on Amozon and Flipkart
-->
Definition
Gets a collection that contains all the columns in the control.
Property Value
The DataGridViewColumnCollection that contains all the columns in the DataGridView control.
Examples
The following code example demonstrates how to create an unbound DataGridView; set the ColumnHeadersVisible, ColumnHeadersDefaultCellStyle, and ColumnCount properties; and use the Rows and Columns properties. It also demonstrates how to use a version of the AutoResizeColumnHeadersHeight and AutoResizeRows methods to properly size the column headers and the rows. To run this example, paste the following code into a form that contains a DataGridView named
dataGridView1
and a button named Button1
, and then call the InitializeDataGridView
method from the form's constructor or Load event handler. Ensure all events are connected with their event handlers.Remarks
By using the DataGridViewColumnCollection returned by this property, you can add columns, remove columns, and obtain a count of the columns contained in the DataGridView control. For more information, see DataGridViewColumnCollection.