RadListControl SelectedIndexChanged Issue

14 posts, 1 answers
  1. Andrew Powrie
    Andrew Powrie avatar
    17 posts
    Member since:
    Apr 2007

    Posted 28 Jul 2010 Link to this post

    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?
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 29 Jul 2010 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Andrew Powrie
    Andrew Powrie avatar
    17 posts
    Member since:
    Apr 2007

    Posted 29 Jul 2010 Link to this post

    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?
  5. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 30 Jul 2010 Link to this post

    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
  6. Andrew Powrie
    Andrew Powrie avatar
    17 posts
    Member since:
    Apr 2007

    Posted 10 Aug 2010 Link to this post

    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?

  7. Answer
    Victor
    Admin
    Victor avatar
    1351 posts

    Posted 10 Aug 2010 Link to this post

    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
  8. Juergen Holzer
    Juergen Holzer avatar
    32 posts
    Member since:
    Mar 2010

    Posted 05 Nov 2010 Link to this post

    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
  9. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 11 Nov 2010 Link to this post

    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
  10. Juergen Holzer
    Juergen Holzer avatar
    32 posts
    Member since:
    Mar 2010

    Posted 11 Nov 2010 Link to this post

    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
  11. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 11 Nov 2010 Link to this post

    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
  12. Juergen Holzer
    Juergen Holzer avatar
    32 posts
    Member since:
    Mar 2010

    Posted 11 Nov 2010 Link to this post

    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.
  13. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 16 Nov 2010 Link to this post

    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
  14. Juergen Holzer
    Juergen Holzer avatar
    32 posts
    Member since:
    Mar 2010

    Posted 17 Nov 2010 Link to this post

    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
  15. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 19 Nov 2010 Link to this post

    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>>
Back to Top
UI for WinForms is Visual Studio 2017 Ready