How can i get the row selected on the right mouse button?
Thanks
or get the row it was right clicked?
Here's a short sample that determines the clicked record based on a mouse event. You can register for this event in XAML or in code. Code sample:
XamDataGrid grid = GetEditorGrid(); grid.PreviewMouseRightButtonDown += OnGridRightMouseButtonDown;
The event handler looks like this:
/// <summary>/// Activates the record under the cursor if the right mouse button/// is pressed./// </summaryprotected virtual void OnGridRightMouseButtonDown(object sender, MouseButtonEventArgs e){ Record record = UIHelper.TryGetClickedRecord(sender, e); if (record != null) { //do something with the record }}
And this is the helper method that returns the record.
/// <summary> /// Gets a grid's clicked record. /// </summary> public static Record TryGetClickedRecord(object sender, MouseButtonEventArgs e) { //get the cursor position and the item under the cursor XamDataGrid grid = (XamDataGrid) sender; Point p = e.GetPosition(grid); DependencyObject obj = grid.InputHitTest(p) as DependencyObject; //if there is nothing under the cursor, return if (obj == null) return null; //check if we're dealing with the presenter itself CellValuePresenter presenter = obj as CellValuePresenter; if (presenter == null) { //look up the visual tree presenter = FindParent<CellValuePresenter>(obj); } //return the presenter's record, if possible return presenter == null ? null : presenter.Record; }
HTH
Philipp
Thanks.