使用vb.net datagridview我已经制作了自动增量列。使用以下代码:
Private Sub Dgv_RowCountChanged()
For Each dgvr As DataGridViewRow In Me.dgvProm.Rows
dgvr.Cells(0).Value = dgvr.Index + 1
Next
End Sub
在我转移到DevExpress xtra网格控件后,我想做同样的事情。我尝试过类似的东西,但这并不好。
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
知道我该怎么做。这是我的第一个问题。
Devexpress 11.1.4,Winforms,网格控制
答案 0 :(得分:0)
对InitNewRow
使用事件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;
}
答案 1 :(得分:0)
好的,经过大量的研究,我似乎找到了解决方案。它是这样的:
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