Question

Hello i have a problem with checkbox in gridcontrol(winforms dexexpress). I have three collumns 'Check','Name', 'Descr'. The user can apply sorting on collumn for example 'Name' and then he checked checkbox('Check') on some row. I want to get checked item after i click checkbox on row. But i get wrong index of the row(it is index with default sorting). Any ideas to get right index after applied sorting? The problem is different checkbox are selected after other collumn sorting. I read about this http://documentation.devexpress.com/#WindowsForms/CustomDocument2531 but it not helps me, really dont know how to do it

    private void gridViewT_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
{
    if (e.Column.Name == "CheckColumn" && e.RowHandle > -1)
    {
        if (e.Value != null && (bool)e.Value) {
            DataRow dr = ((DataTable)gridControlT.DataSource).Rows[e.RowHandle];
            DoSomeThing(dr);
        }
    }
}

So the e.RowHandle(which means index to table) is after sorting by another collumn old. The CheckColumn which is column with checkboxes is not sorted by another collumn.

Was it helpful?

Solution

Here is the correct code:

//DataRow dr = ((DataTable)gridControlT.DataSource).Rows[e.RowHandle];
DataRow dr = ((GridView)sender).GetDataRow(e.RowHandle);

Row handle gets the handle(not the index) of the row that contains the processed cell. Row handles define the order in which rows are displayed within a View. This order takes into account any sorting and filtering settings applied to the View.

Related help-article : Identifying Rows and Cards

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top