简体   繁体   中英

Rows selection in GridControl DevExpress

In DevExpress 13 GridControl.TableView with a dynamic list when a row is deleted the row selection doesn't dissapear. It remains on the row which replaced the deleted one. When the selected row is deleted, how can I make the row selection dissapear automatically too? I tried to implement it through GridControl.BeginDataUpdate and GridControl.EndDataUpdate., dut it does not work.

private bool _isAlreadyLoaded = false;

private void GridControl_OnLoaded(object sender, RoutedEventArgs e)
{
    if (ThisViewModel != null
        && _isAlreadyLoaded == false)
    {
        ThisViewModel.GettingNewRow += RefreshCommSessionsList;

        _isAlreadyLoaded = true;
    }
}
//InitializeDataList - method that getting List for GridControl.TableView

public void RefreshCommSessionsList()
{
    App.Current.Dispatcher.Invoke(() =>
    {
        var a = GridControl.GetSelectedRowHandles();
        int selectedRowHandle = -1;
        if (a.Any())
        {
            selectedRowHandle = GridControl.View.FocusedRowHandle;
        }
        GridControl.BeginDataUpdate();
        if (NewRowCount < 5 && ThisViewModel != null)
        {
            ThisViewModel.InitializeDataList();
            TableView.DataControl.SelectItem(selectedRowHandle);
        }
        else
        {
            GridControl.RefreshData();
            TableView.DataControl.SelectItem(selectedRowHandle);
        }
        GridControl.EndDataUpdate();
        NewRowCount++;
    });
}

Thank you!

You can use GridControl.CurrentItem property. If you set its value to null then the row selection will dissapear.

GridControl.CurrentItem = null;

To change the FocusedRow of a Grid, use the GridView!

So if your GridView is named the same as your GridControl it would go as follows,

GridView.FocusedRowChanged(null, null);
//Replace "GridView" with your GridView's name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM