我有一個從DataTable填充的XCeed Datagrid。當用戶雙擊一個單元格時,我希望能夠確定從哪一行中選擇了哪一列。我怎麼做?如何確定在XCeed Datagrid中哪個列被雙擊?
0
A
回答
1
那麼,現在看來,簡潔地提出問題是受到懲罰的,我根本看不出提供任何代碼的意義。
該解決方案確實(可笑)複雜,對WPF的作者感到羞恥。
The solution for a standard WPF DataGrid can be found here.
我返工你要處理的DATACELL目標雙擊該解決方案爲XCeed DataGridControl(在VB)
Public Class MyXAMLWindow
Private Sub grdResults_MouseDoubleClick(sender As Object, e As MouseButtonEventArgs)
'Cast the sender parameter to the XCeed DataGridControl'
Dim dg As Xceed.Wpf.DataGrid.DataGridControl = sender
'Extract the cell information to a custom CellInfo structure.'
Dim info = GetCellInfo(e.OriginalSource, dg.SelectedIndex)
'Pass the cellinfo to the ViewModel'
dg.DataContext.SelectedInfo = info
End Sub
''' <summary>
''' Contructs a <see cref="CellInfo(Of String)">cellinfo</see> structure from the cell that was clicked.
''' </summary>
''' <param name="originalSource">The value of the OriginalSource property of the MouseButtonEventArgs.</param>
''' <param name="rowIndex">The index of the row on which was clicked.</param>
''' <returns><see cref="CellInfo(Of string)">cellinfo</see> object.</returns>
''' <remarks>This function uses the OriginalSource property of the MouseButtonEventArgs as a starting point.</remarks>'
Private Function GetCellInfo(originalSource As Object, rowIndex As Integer) As CellInfo(Of String)
Dim dep As DependencyObject = originalSource
Dim cellInfo = New CellInfo(Of String)
'Find the DataCell that is associated with the original source.'
While (dep IsNot Nothing) AndAlso Not (TypeOf dep Is DataCell)
dep = VisualTreeHelper.GetParent(dep)
End While
If dep Is Nothing Then
Return New CellInfo(Of String) With {.ColumnIndex = -1, .RowIndex = -1, .Value = String.Empty}
End If
If TypeOf dep Is DataCell Then
Dim cell As DataCell = TryCast(dep, DataCell)
cellInfo.ColumnIndex = cell.ParentColumn.Index
cellInfo.RowIndex = rowIndex
cellInfo.Value = cell.Content
End If
Return cellInfo
End Function
End Class
'A custom Structure to hold the data of the selected Cell.'
Public Structure CellInfo(Of TValue)
Public RowIndex As Integer
Public ColumnIndex As Integer
Public Value As TValue
End Structure
0
第一。要做到這一點在後面的文件中的代碼,你可以寫
EventManager.RegisterClassHandler(
typeof(DataCell),
DataCell.MouseDoubleClickEvent,
new MouseButtonEventHandler(OnDataCellMouseDoubleClick));
下一頁去處理方法:
private void OnDataCellMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
var clickedCell = sender as DataCell;
var row = clickedCell.ParentRow;
var rowNum = row.TabIndex;
var column = clickedCell.ParentColumn;
var columnNum = column.Index;
}
相關問題
- 1. 去除Xceed DataGrid中
- 2. 檢測哪個ChartArea被雙擊
- 3. Xceed WPF Datagrid在每個頁面上打印固定列
- 4. 如何確定使用tablesorter在表中單擊哪個列?
- 5. 確定列表中的哪個項目被點擊 - javascript
- 6. 多個提交按鈕,如何確定哪個被點擊?
- 7. 確定在java中雙擊
- 8. 如何定義哪個ListView被點擊?
- 9. 確定哪個JavaFX ListView項目未被選中而被點擊
- 10. Xceed DataGrid QueryableSource和DbContext
- 11. Xceed DataGrid SelectedItem問題
- 12. 你如何確定哪個SKSpriteNode被點擊?
- 13. .NET - 如何確定哪個Model3DGroup已被點擊?
- 14. Android小部件:如何確定哪個按鈕被點擊?
- 15. 如何確定哪個節點被點擊。 Silverlight treeview
- 16. 如何確定哪個按鈕被點擊gridview
- 17. GWT CELLTABLE pager如何確定哪個按鈕被用戶點擊?
- 18. 如何確定哪個按鈕被點擊?
- 19. 如何確定哪個按鈕被點擊了一段時間
- 20. 如何確定哪個按鈕已被點擊jquery
- 21. DataGrid - 綁定雙列到列
- 22. 如何確定哪個「+」鍵被按下?
- 23. 如何確定點擊哪個MKAnnotation?
- 24. 如何更改Xceed Datagrid的CellErrorStyle?
- 25. 如何綁定xceed datagrid中的組合框的Itemssource
- 26. Xceed Datagrid不會綁定到Xceed控件的DataTemplate
- 27. 如何確定單個窗體中的哪個按鈕被點擊
- 28. .NET WPF確定選擇哪個Datagrid
- 29. 確定哪些按鈕被點擊
- 30. 如何雙擊DataGrid區域內的AttachedCommandBehavior
請參閱[「怎麼問」(http://stackoverflow.com/help/how-問問題),然後在StackOverflow中發佈問題。 –