I am new to Telerik and is trying to run the selection changed event for my gridview when select different rows. I have the code for the function, but I do not have the code to call this event. I know the event code for the button is generated in the designer.cs when I double click on the button in the form, but how do I generate an event for selection changed and other events which I cannot see? Do I have to add it in to the Designer manually?
private void gvUser_SelectionChanged(object sender, Telerik.WinControls.UI.SelectionChangedEventArgs e)
7 Answers, 1 is accepted
I tried the following code.
gvUser.SelectionChanged += new Telerik.WinControls.UI.SelectionChangedEventHandler(gvUser_SelectionChanged);
it doesn't work
Thank you for writing.
The SelectinChanged event should be visible and available in the designer. For reference, I am sending you a screenshot of the setup on my end.
In case you are trying to subscribe to the event programmatically, you would need to change the type of the delegate from SelectionChangedEventArgs to EventArgs. Please find below my code snippet for subscribing to the event at run time:
I hope this helps. Should you have further questions please do not hesitate to write back.
I have subscribed to the radGridView1_SelectionChanged event and it works as expected with the exception of when a filter is applied. I would expect that if the selected row is "filtered out" this event would fire.
The issue I am having is that when the selection changes, I pull other records that are associated with the bound datasource for the selected item. When filtering, I expect the selection to be none and be able to clear the previously pulled records.
I am using Telerik Winforms version 2015.2.728.40
Thank you for writing.
The selection in RadGridView is removed at the moment you start editing the filter cell. This is the behavior by design. The SelectionChanged event does not fire when a row has been filtered out simply because by the time the FilterChanged event has fired the SelectedRows collection had been emptied.
In order to achieve your task, you would need to cache the selected rows every time when a filter cell is about to be edited. Then, if any of the cached rows is filtered out you can raise a custom event, for example, and be notified. I am sending you attached a project demonstrating a sample approach.
I hope this helps. Please let me know if you need further assistance.
Thank you very much for the fast response and your explanation. Looks like your sample workaround should be good but it is still a workaround. I will likely implement the suggestion but wanted to note the following which doesn't make sense based on your explanation.
The above code should come back as false when a selected row is filtered out, but it actually shows as true even when the display is empty.
I took at look at your sample approach to resolve the selection change issue. Since I will be doing a combination of filtering by using the icon and text box on the column header as well as in code by using CompositeFilterDescriptor, I need to implement a slightly different workaround.
Thanks for your help,
Thank you for the update.
If I understand correctly you have found a solution fitting your scenario.
Please let me know if you need further assistance.