如何在 wpf 中单击开发快递网格控制单元格



我有一个wpf应用程序,我在其中使用DevExpress GridControl和TableView。我的问题是我想获取点击的单元格。我在其他帖子中找到了该解决方案:

private void TableView_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        TableViewHitInfo hitInfo = tableView.CalcHitInfo(e.GetPosition(MainControl));
        if (hitInfo.InRowCell)
        {
            object value = gridControl.MainView.GetRowCellValue(hitInfo.RowHandle, hitInfo.Column);
            //...
        }
    }

但是网格控件没有名为 MainView 的属性。我做错了什么?或者你有其他解决方案来解决我的问题?

用于获取单元格值的正确代码片段应如下所示:

<dxg:GridControl ItemsSource="{Binding ...">
    <dxg:GridControl.View>
        <dxg:TableView AllowEditing="False" 
                       MouseLeftButtonUp="TableView_MouseLeftButtonUp"/>
    </dxg:GridControl.View>
</dxg:GridControl>

void TableView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {
    TableView tableView = sender as TableView;
    TableViewHitInfo hitInfo = tableView.CalcHitInfo(e.OriginalSource as DependencyObject);
    if (hitInfo.InRowCell) {
        object value = tableView.Grid.GetCellValue(hitInfo.RowHandle, hitInfo.Column);
        // do something
    }
}

相关帮助文章:获取和设置单元格值

MainView 是 GridControl 在此示例中使用的视图的名称。如果您已重命名或命名视图,否则显然还需要更改代码以使用该名称:

object value = MyGridControl.MyGridView.GetRowCellValue(hitInfo.RowHandle, hitInfo.Column);

或更容易,因为视图应该已经在范围内:

object value = MyGridView.GetRowCellValue(hitInfo.RowHandle, hitInfo.Column);

最新更新