Search code examples
vb.netdevexpressxtragrid

Create autoIncrement column using Devexpress xtragrid


Using vb.net datagridview I have made autoincrement column. Using the following code:

    Private Sub Dgv_RowCountChanged()
          For Each dgvr As DataGridViewRow In Me.dgvProm.Rows
          dgvr.Cells(0).Value = dgvr.Index + 1
    Next
    End Sub

After I moved to DevExpress xtra grid control I wanted to do the same thing. I have try something like this but it is not good.

        Private Sub GridView1_RowCountChanged(sender As Object, e As EventArgs) Handles GridView1.RowCountChanged
    For Each dgvr As XtraGrid.Views.Grid.GridRow 

        Dim s As String = dgvr.VisibleIndex + 1
        MessageBox.Show(s)
    Next

End Sub

Any idea how can i do this. This is my first question here.

Devexpress 11.1.4 , Winforms, Grid control


Solution

  • Ok , after a lot of research I seem to have found a solution. It goes like this:

     Private Sub GridView1_InitNewRow_1(sender As Object, e As InitNewRowEventArgs) Handles GridView1.InitNewRow
    
            ' auto increment first column
            GridView1.SetRowCellValue(e.RowHandle, "COLUMN", GridView1.RowCount + 1)   ' I want to start from one
    
        End Sub