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

RadListControl SelectedIndexChanged Issue

13 Answers 380 Views
ListControl
This is a migrated thread and some comments may be shown as answers.
Andrew Powrie
Top achievements
Rank 1
Andrew Powrie asked on 28 Jul 2010, 11:47 PM
On ListControl with SelctionMode MultiSimple the SelectedIndexChanged event fires whenever an item is selected, but only fires on de-selection when the items are de-selected in the reverse order that they were selected in. It's as if when selecting items it forms a stack (firing the event on each select) and when de-selecting items the event only fires if the item on the top of the stack is de-selected).  Is there another event I should be using?

13 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 29 Jul 2010, 12:22 PM
Hello Andrew Powrie,

Thank you for writing.

This behavior is by design. We decided to change the current position of the currency manager when the item at the current position was deselected in order to avoid the case in which the current position points to an item that is not selected. Is this behavior inconvenient? If it is please explain in more detail what your goal is and we will consider providing a way to modify this behavior.

I am looking forward to your reply.
 
Greetings,
Victor
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
Andrew Powrie
Top achievements
Rank 1
answered on 29 Jul 2010, 09:56 PM
I would like to know when any item is selected or de-selected, no matter what the situation, via the SelectedIndexChanged event as this is exactly what the MicroSoft ListBox control behaviour is. What is the point of SelectedIndexChanged event if it will only fire in certain situations on de-selection?
0
Victor
Telerik team
answered on 30 Jul 2010, 05:34 PM
Hello Andrew Powrie,

Thank you for clarifying.

The point of SelectedIndexChanged is that only one of the selected items has the current index. When you deselect an item different than the one with the current index, SelectedIndexChanged will not fire. This is semantically correct, the Microsoft ListBox control fires SelectedIndexChanged every time you select something, event if it is the same item. In order to listen for when an Item's Selected state changes you have to subscribe to RadListControl's DataItemPropertyChanged event. This event is not yet available but will be available in the Q2 service pack. It will provide information about which item changed and what the new and old values are.

I would like to thank you for your invaluable feedback on the list control. Your Telerik points have been updated.
 
Sincerely yours,
Victor
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
Andrew Powrie
Top achievements
Rank 1
answered on 10 Aug 2010, 05:21 AM

I have just loaded SP1 as the release history states that the DataItemPropertyChanged event is now available. Is there some sample code to show how to use the DataItemPropertyChanged event as I cannot see it to add to my control in the VS2008 designer?

0
Accepted
Victor
Telerik team
answered on 10 Aug 2010, 04:48 PM
Hello Andrew Powrie,

Thank you for writing.

Please refer to the following snippet:
 
void ListElement_DataItemPropertyChanged(object sender, RadPropertyChangedEventArgs e)
{
    if (e.Property == RadListDataItem.SelectedProperty)
    {
        bool newVal = (bool)e.NewValue;
        // do something with the new value.
    }
}
 
Subscribing to this event looks like so:
 
this.radListControl1.ListElement.DataItemPropertyChanged += new RadPropertyChangedEventHandler(ListElement_DataItemPropertyChanged);
 
this.radDropDownList1.ListElement.DataItemPropertyChanged += new RadPropertyChangedEventHandler(ListElement_DataItemPropertyChanged);
 
Please write again if you need further assistance.

Sincerely yours,
Victor
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
Juergen Holzer
Top achievements
Rank 2
answered on 05 Nov 2010, 04:59 PM
Hello!

I have same issue with selecting an item in ListControl. But the DataItemPropertyChanged Event is not a solution for me, because it fires to often and I didn't find an easy way to fire it programmatically.

Maybe you can tell me another solution for this.

Thanks!
Kind regards
Juergen
0
Peter
Telerik team
answered on 11 Nov 2010, 10:33 AM
Hello Juergen,

Thank you for contacting us.

Could please explain your scenario in greater detail? I am not sure that I understand the meaning of 'firing an event programmatically'. This information will allow me to assist you further.
 
I looking forward for your reply.

Best wishes,
Peter
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
Juergen Holzer
Top achievements
Rank 2
answered on 11 Nov 2010, 10:54 AM
Hello Peter,

Thanks for your answer.

Here is my scenario:

I have multiple listcontrols (with multiselection enabled) and a method which gets a RadListDataItem. So I get to know which Item was last selected I have to store it in a reference. This is easy done by using selectedIndexChanged or selectedItemChanged Events but as I do a right click (for conextmenu) no event is fired. So I have to use the MouseDown event and check which button was pressed (in fact of multiselection) and select the Item. But as I set SelectedItem no event is fired, if the item was even selected before.

Hope my english is not to bad and you understand my explanation.
best regards,
Juergen
0
Richard Slade
Top achievements
Rank 2
answered on 11 Nov 2010, 11:24 AM
Hello Juergen,

I just want to confirm what you are trying to do. Is it correct to say that when you right click on one of the data items in your RadListBox, you wish for that item to become selected or deselected?

Richard
0
Juergen Holzer
Top achievements
Rank 2
answered on 11 Nov 2010, 11:28 AM
This thing I have done. But the problem is, if the Item was selected before no Event is fired. But I need the Event fired every time an item is selected.
0
Peter
Telerik team
answered on 16 Nov 2010, 02:30 PM
Hi Juergen,

Thank you for the clarification.

In case that you want to know when RadListDataItem is selected or unselected, I recommend selecting/unselecting an item by setting the value of Selected property and subscribe to the DataItemPropertyChanged event.

Setting the value of the Selected property will always fire the DataItemPropertyChanged event.

Please refer to the code snippet below:

private void Form1_Load(object sender, EventArgs e)
{
            this.radListControl1.SelectionMode = SelectionMode.MultiSimple;
            this.radListControl1.ListElement.DataItemPropertyChanged += new Telerik.WinControls.RadPropertyChangedEventHandler(ListElement_DataItemPropertyChanged);
}
 
RadListDataItem lastSelected = null;
void ListElement_DataItemPropertyChanged(object sender, Telerik.WinControls.RadPropertyChangedEventArgs e)
{
            if (e.Property != RadListDataItem.SelectedProperty)
            {
                return;
            }
 
            RadListDataItem checkedItem = (RadListDataItem)sender;
            bool isChecked = (bool)e.NewValue;
 
            MessageBox.Show(checkedItem.Text + " checked state is " + isChecked);
 
            if (isChecked)
            {
                this.lastSelected = checkedItem;
            }
}

I hope this helps. If you have any other questions or comments, please let me know.

All the best,
Peter
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
Juergen Holzer
Top achievements
Rank 2
answered on 17 Nov 2010, 05:52 PM
Hello Peter!

Thanks for the snippet. It doesn't fit exactly what I expect, but I think I can get it using your sample.

Regards
Juergen
0
Peter
Telerik team
answered on 19 Nov 2010, 04:03 PM
Hi Juergen Holzer,

I am glad to hear that this solution works for you. Thank you for your feedback. We will consider implementing such event in one of our upcoming releases.

Do not hesitate to contact me if you have any other questions.

Sincerely yours,
Peter
the Telerik team
See What's New in RadControls for WinForms in Q3 2010 on Wednesday, November 17, 11am Eastern Time: Register here>>
Tags
ListControl
Asked by
Andrew Powrie
Top achievements
Rank 1
Answers by
Victor
Telerik team
Andrew Powrie
Top achievements
Rank 1
Juergen Holzer
Top achievements
Rank 2
Peter
Telerik team
Richard Slade
Top achievements
Rank 2
Share this question
or