【问题标题】:How to get DevExpress GridControl cell clicked in wpf?如何在 wpf 中单击 DevExpress GridControl 单元格?
【发布时间】:2015-06-18 09:57:03
【问题描述】:

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

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 的属性。我做错了什么?或者您对我的问题有其他解决方案吗?

【问题讨论】:

    标签: c# wpf devexpress tableview gridcontrol


    【解决方案1】:

    获取单元格值的正确code-sn-p应该是这样的:

    <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
        }
    }
    

    相关帮助文章:Obtaining and Setting Cell Values

    【讨论】:

      【解决方案2】:

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

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

      或者更简单,因为视图应该已经在范围内:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-07
        相关资源
        最近更新 更多