views:

345

answers:

4

Hi

Is there a way for a right click event to select a row in toolkit datagrid?

I'm using toolkit context menu which works nicely, but the problem is, only left click is able to select rows, and I need right click to be able to do that if I want my context menu to work properly.

Any help is appreciated

+4  A: 

You can find a solution here.

Basically it goes like this:

private void dg_LoadingRow(object sender, DataGridRowEventArgs e)
{
    e.Row.MouseRightButtonDown += new MouseButtonEventHandler(Row_MouseRightButtonDown);
}
void Row_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
    dg.SelectedItem = ((sender) as DataGridRow).DataContext;
}
Koynov
It's too bad we have to use hacks like this, but I suppose it's better than nothing. Thanks
VexXtreme
A: 

Thank you, that makes a lot of sense. I still do not understand the syntax to access the contents of the cells in the row from the code behind. Can you show me what the basic syntax is please?

Also, is there any way to detect which column was clicked?

Andrew Lindzon
A: 

Thanks good idea. But the with UnloadingRow event could have been more effective had been specified.

private void dg_UnloadingRow(object sender, System.Windows.Controls.DataGridRowEventArgs e)
{
    e.Row.MouseRightButtonDown -= Row_MouseRightButtonDown;
}
Orkun Genel
+1  A: 

This open source project on Codeplex supports this behavior out of the box and does much more than this:

http://sl4popupmenu.codeplex.com/

Ziad