【问题标题】:Rows selection in GridControl DevExpressGridControl DevExpress 中的行选择
【发布时间】:2020-10-10 02:03:23
【问题描述】:

在 DevExpress 13 GridControl.TableView 中,当删除行时,行选择不会消失。它保留在替换已删除行的行上。删除所选行时,如何使行选择也自动消失? 我尝试通过GridControl.BeginDataUpdate和GridControl.EndDataUpdate来实现它,但它不起作用。

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++;
    });
}

谢谢!

【问题讨论】:

    标签: c# .net wpf devexpress gridcontrol


    【解决方案1】:

    您可以使用GridControl.CurrentItem 属性。如果将其值设置为null,则行选择将消失。

    GridControl.CurrentItem = null;
    

    【讨论】:

      【解决方案2】:

      要更改网格的 FocusedRow,请使用 GridView!

      因此,如果您的 GridView 与您的 GridControl 命名相同,它将如下所示,

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-29
        • 1970-01-01
        • 1970-01-01
        • 2013-05-07
        相关资源
        最近更新 更多