This is a migrated thread and some comments may be shown as answers.

Multiple selection and context menus in Q1 2010

4 Answers 180 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ludovic Gerbault
Top achievements
Rank 1
Ludovic Gerbault asked on 12 Mar 2010, 05:07 PM
Hi

In my scenario, I'm supposed to attach a context menu on the rows of a raadgridview.

This context menu allows to perform various actions on the selected row.

But the thing is that my scenario include also the possibility of executing such action on multiple rows at once.

It was all working fine on the Q3 2009, but in Q1 2012, it seems that the multiple selection mechanism change.

I did some research and then set the SelectionMode to Extended, which gave me back the possibility of multiple selection on the grid, but when I right click to access the context menu, the grid unselect all rows except the one I used the right click on, which completely breaks my scenario.

How can I get this functionnality back ?

4 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 18 Mar 2010, 11:37 AM
Hi Subileau Pascal,

That is very strange. I tried to reproduce the problem but I could not. I am sending you a sample application which has a grid with extended selection and a RadContextMenu in use. Could you please run the application and try to reproduce the problem? 


All the best,
Milan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ludovic Gerbault
Top achievements
Rank 1
answered on 18 Mar 2010, 05:59 PM
Well, i downloaded your sample and tried it, and your sample doesn't have the issue I'm having.

I tried modifying it to match my own and reproduce the issue, without success so far.

But my grid is really complex, it's hard to find out what's causing the problem.

But anyway, I still can't have a contextmenu on a multiple selection in my application.
0
Accepted
Milan
Telerik team
answered on 22 Mar 2010, 06:20 PM
Hello Subileau Pascal,

A similar issue was reported by another customer and we were able to offer him a quick fix. In his solution some custom code was executed when RadContextMenu is opened:

private void RadContextMenu_Opened(object sender, RoutedEventArgs e)
{
    RadContextMenu menu = (RadContextMenu)sender;
    GridViewRow row = menu.GetClickedElement<GridViewRow>();
  
    if (row != null)
    {
        if (!RadGridView1.SelectedItems.Contains(row.Item))
            RadGridView1.SelectedItems.Clear();
  
        row.IsSelected = row.IsCurrent = true;
  
        GridViewCell cell = menu.GetClickedElement<GridViewCell>();
        if (cell != null)
        {
            cell.IsCurrent = true;
        }
    }
    else
    {
        menu.IsOpen = false;
    }
}

I am not sure you have such code in your application but in case you do you could try the following solutions:

By default RadGridView will sync its CurrentItem and SelectedItem. As a result whenever "row.IsSelected = row.IsCurrent = true;" is executed and the clicked item is not current , RadGridView will set it as current. Once a new CurrentItem is set the grid will try to sync SelectedItem - new SelectedItem will be set which ultimately deselects all other items.

There are two possible workarounds - the first one involves setting IsSynchronizedWithCurrentItem to false. With that setting set to false RadGridView will not try to sync SelectedItem when CurrentItem is changed and the selection will not be cleared.

The other approach is to remove the line which is changing the current item:

row.IsSelected = row.IsCurrent = true;

Hope this information will help you solve the problem.

All the best,
Milan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ludovic Gerbault
Top achievements
Rank 1
answered on 23 Mar 2010, 09:21 AM
Indeed, I had a similar code on the open event, I removed it (it wasn't being used anyway), and my scenario works again.

Thanks a lot.
Tags
GridView
Asked by
Ludovic Gerbault
Top achievements
Rank 1
Answers by
Milan
Telerik team
Ludovic Gerbault
Top achievements
Rank 1
Share this question
or