Reputation: 17
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
Upvotes: 0
Views: 2361
Reputation: 17
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
Upvotes: 0
Reputation: 5890
Use event InitNewRow
for the GridView
.
private void gv_InitNewRow(object sender, InitNewRowEventArgs e)
{
var myobject = gv.GetRow(e.RowHandle) as MyType;
var previousmax = /* sth */ <- you can use gv.RowCount or something else
myobject.NewValue = previousmax + 1;
}
Upvotes: 0