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

GridViewSelectColumn header click event

8 Answers 171 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 18 May 2011, 08:27 AM
Short version:
I have a RadGridView with a GridViewSelectColumn.
I am trying to intercept the click event on header, so that I can programmatically do what I need.

Long version:
My grid has multiple pages of data. I am manually tracking the selections between pages. When I click the header, I want to intercept that event so that I can go and update my own tracking lists.

8 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 18 May 2011, 08:35 AM
Hi David,

Please, use SelectionChanged event to track selection changes. 

Regards,
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
David
Top achievements
Rank 1
answered on 18 May 2011, 08:44 AM
But that will not indicate to me if it was the checkbox in the header that was clicked. Or if the user instaclicked a whole bunch of rows
0
Milan
Telerik team
answered on 18 May 2011, 09:25 AM
Hello David,

What would be the difference between the user clicking on the header and the user clicking on a row? Regradles, you can try the following:

public MainPage()
{
    InitializeComponent();
  
    this.MouseRightButtonDown += new MouseButtonEventHandler(MainPage_MouseRightButtonDown);
}
  
  
  
void playersGrid_RowLoaded(object sender, RowLoadedEventArgs e)
{
    var row = e.Row as GridViewHeaderRow;
  
    if (row != null)
    {
        var checkBox = row.Cells[0].Content as CheckBox;
  
        checkBox.Checked += new RoutedEventHandler(checkBox_Checked);
    }
}
  
void checkBox_Checked(object sender, RoutedEventArgs e)
{
    throw new NotImplementedException();
}


Regards,
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
David
Top achievements
Rank 1
answered on 19 May 2011, 12:59 AM
What would be the difference? there is a massive difference.
Going back to my original post, I have data over multiple pages.

So I want to be able to capture the event that the user clicked on the header to "select all". So that I can execute my own custom logic.
The data hasn't even been loaded yet as it comes from RIA Services. So I DO need that click event so that I can execute my own custom 'select all' logic.
0
Patrice VIALOR
Top achievements
Rank 1
answered on 23 May 2011, 03:17 PM
I have the same goal : implement my own multi-page custom selection logic.
And overriding, or recreating a custom GridViewSelectColumn is impossible since :

This GridViewColumn method is internal.
internal virtual void OnOwnerChanged(GridViewDataControl oldOwner, GridViewDataControl newOwner){}

Then this getter / setter on the GridViewColumn is not virtual :
public GridViewDataControl DataControl {get;internal set;}

So it is impossible to attach to the grid.Items.CollectionChanged event from within the GridColum, because we don't have control on when does the grid is attached. (And the grid isn't attached in the constructor...)

Is it possible for you to let people override theses properties / methods ??? (Or give a workaround, but I don't believe it is possible...)

Thanks in advance,

Bests,
0
Patrice VIALOR
Top achievements
Rank 1
answered on 23 May 2011, 03:43 PM
Letting people override the CompositeSelectionHandler in the GridViewDataControl Constructor should be another way to give developers a means to implement their own selection logic. An ICompositeSelectionHandler interface would be great !!!
0
Patrice VIALOR
Top achievements
Rank 1
answered on 24 May 2011, 08:44 AM
Ok,

I have successfully implemented a custom selection behavior by creating a CustomGridViewSelectColum based on the GridViewSelectColumn orinigal code, but the tricks I do is not what I can consider like a clean and efficient code : The problem was to detect a "single row click" into my grid.SelectionChanged handler, in order to implement a "global" unselection of all the lines on all the pages. The only mean I found to detect the internal grid selection code was doing such an action was this one : introspect the call stack...

System.Diagnostics.StackTrace stack = new System.Diagnostics.StackTrace();
                foreach (System.Diagnostics.StackFrame s in stack.GetFrames())
                {
                    if (s.ToString().Contains("PerformRowSelection"))
                    {
                        this.GlobalSelectedItems.Clear();
                        foreach (object obj in this.grid.SelectedItems)
                            this.GlobalSelectedItems.Add(obj);
                        return;
                    }
                }

PerformRowSelection is an internal CompositeSelectionHandler function, called when a single selection is clicked and all but this selection must be unselected. And it seems there are no ways to detect when this behavior is used... but this tricks...

However this tricks is runtime heavy. So please Telerik, could you imagine a way to let people implement their own selection logic, or at least, give a way to detect some events like "OnSelectAllLineButTheses"...

Thanks in advance.

Bests,
0
Milan
Telerik team
answered on 24 May 2011, 10:04 AM

Hello Raphaël,

We are researching this possibility but the intricacy of event handling and selection mechanism makes this task very difficult.

Hopefully we will be able to provide more flexibility on that front in a feature release. 

Thank you so much for your feedback.



Kind regards,
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
Tags
GridView
Asked by
David
Top achievements
Rank 1
Answers by
Milan
Telerik team
David
Top achievements
Rank 1
Patrice VIALOR
Top achievements
Rank 1
Share this question
or