David ChopperField David ChopperField - 1 month ago 11
C# Question

How to make the new added unbound column value auto number become static?

First I make an unbound column in

GridView
(using DevExpress):

public void buttonl_Click(object sender, EventArgs e)
{
//GridColumn clmn = gridaaa.Columns["code"];

if (gridaaa.Columns.ColumnByFieldName("idx") != null)
{
gridaaa.Columns.ColumnByFieldName("idx").Dispose();
}



GridColunn unbColumn2 = gridaaa.Columns.AddField("idx");
unbColumn2.VisibleIndex = gridaaa.Columns.Count;
unbColumn2.UnboundType = DevExpress.Data.UnboundColumnType.Integer;
//// Disable editing.
unbColumn2.OptionsColunn.AllowEdit = false;
// gridaaa.Columns.ColumnByFieldName("idx").Dispose();
}


In the
gridView1_CustomUnboundColumnData
event I am using this code

private void gridView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e)
{

if (e.Column.FieldName == "idx")
{
e.Value = e.ListSourceRowIndex;
}
}


for the output or result was:

index column

The question is how to make the index or idx column value become static when I click sorting in any column header. As you can see when I click genre header the value follow with code or index in database, I want to make it like autonumber from 0 whenever I keep click column header of genre or anything:

enter image description here

Answer

You can use ColumnView.GetRowHandle method to get the handle of current row which is always reflects to the position of row in GridView from up to down.

Here is example:

private void gridView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e)
{
    if (e.Column.FieldName == "idx")
        e.Value = gridView1.GetRowHandle(e.ListSourceRowIndex);
}
Comments