Question

problem is , that whenever the grid's row is right clicked the selected item is null.how do i make a the grid's row selected when any row was right clicked?

thanks Jamal

Was it helpful?

Solution

I think the solution may have a problem. Every time a row is loaded it will add an event handler, so if the row is ever reused it can accumulate event handlers. I would recommend removing the event handler when the row is unloaded. Here's my suggested code:

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;
}
// new portion
private void dg_UnloadingRow(object sender, DataGridRowEventArgs e)
{
    e.Row.MouseRightButtonDown -= new MouseButtonEventHandler(Row_MouseRightButtonDown);
}

OTHER TIPS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top