Home Forums WPF controls Xceed DataGrid for WPF ContextMenu problem

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #22264 |

    Hi,

    I’m trying to produce a context sensitive right-click menu so that when the user right-clicks on the DataGridControl I can pick up what row and column they’ve clicked on and produce a custom context menu.

    I’m using the ContextMenuOpening event to capture the right-click and that’s working great however the DataGridControl.CurrentItem property doesn’t contain the item over which the mouse was right-clicked. It contains either null (if no item has yet been selected) or the last item that was selected.

    So, is there any way to make the DataGridControl select an item when the right mouse button is clicked?

    Thanks in advance for any help,
    Cheers,
    Terry.

    Imported from legacy forums. Posted by Terry (had 4598 views)

    Xceed Support
    Member
    Post count: 5658

    You can always register a class handler on the DataRow/DataCell class(es) and in the Handler you can set the Data Item as current.

    <code>
    myDataGridControl.CurrentColumn = myCell.ParentColumn;
    object dataItem = myDataGridControl.ItemContainerGenerator.ItemFromContainer( myCell.ParentRow);
    myDataGridControl.CurrentItem = dataItem;
    </code>

    Imported from legacy forums. Posted by Marcus [Xceed] (had 395 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks, I’ll try that.

    Cheers,
    Terry.

    Imported from legacy forums. Posted by Terry (had 3337 views)

    User (Old forums)
    Member
    Post count: 23064

    for which event we are going to add your code..?

    Imported from legacy forums. Posted by bdmsoft (had 415 views)

    User (Old forums)
    Member
    Post count: 23064

    For those who still experience a similar issue, I’ve found another more elegant approach

    <DataGrid:DataGridControl.Resources>
                <Style TargetType=”{x:Type DataGrid:DataRow}”>
                  <EventSetter Event=”MouseRightButtonDown” Handler=”OnMouseRightButtonDown” />
                </Style>
    </DataGrid:DataGridControl.Resources>

    Method OnMouseRightButtonDown will be triggered every time you rightclick on the row in the grid.

    Imported from legacy forums. Posted by Kyrylo (had 1949 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.