Very often you would like a column in your Xtragrid to be entered a new value automatically whenever a new row is added to the grid. This column is usually the first column in your grid.
This can be done by using the CustomColumnDisplayText event in your grid view.
Open your form design. Click your gridview and press F4 to open its properties Window. Choose the Events tab.
Locate the CustomColumnDisplayText event and double click it. In the handling event codes make it look like the following:
CSharp code
private void yourGridView_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e) {
if (e.Column == yourColName) { // without " before and after yourColName
if (e.RowHandle >= 0) {
e.DisplayText = (e.RowHandle + 1).ToString();
}
}
}
VB Code
Private Sub yourGridView_CustomColumnDisplayText(ByVal sender As System.Object, ByVal e As
DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs) Handles gvNhanVien.CustomColumnDisplayText
If (e.Column.FieldName = "yourColName") Then
If e.RowHandle >= 0 Then
e.DisplayText = (e.RowHandle + 1).ToString()
End If
End If
End Sub
1 comment:
Muchas Gracias!!!
Gloria Ochoa
Colombia
Post a Comment