![](/img/trans.png)
[英]How to get the content of a DevExpress GridControl in XAML from C# in WPF
[英]How to get DevExpress GridControl cell clicked in 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在此示例中使用的View的名稱。 如果您已重命名或命名視圖,則顯然您還需要更改代碼以使用該名稱:
object value = MyGridControl.MyGridView.GetRowCellValue(hitInfo.RowHandle, hitInfo.Column);
或更容易,因為視圖應該已經在范圍內:
object value = MyGridView.GetRowCellValue(hitInfo.RowHandle, hitInfo.Column);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.