21/09/2011

How to create a serial number in Datagrid vb.net code?

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 :



  1. 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
            e.Value = e.RowIndex + 1
        End If
    End Sub


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 
Happy coding




No comments:

Post a Comment

What & How