SelectionChanging problem

5 posts, 1 answers
  1. Fredrik
    Fredrik avatar
    54 posts
    Member since:
    Sep 2010

    Posted 13 Jun 2011 Link to this post

    Hi !!!

    In my SelectionChanging Event isn´t the selecteditem supposed to be the current item and not the selected one ?
    If I watch my sender property then the selecteditem is always the newly selected one and not the current item.
    Trying to implement some logic before changing to the new selecteditem.

    Regards

    Fredrik

    P.s Running version 2011.1.420.1037 of Controls.Input D.s
  2. Deyan
    Admin
    Deyan avatar
    2037 posts

    Posted 14 Jun 2011 Link to this post

    Hello Fredrik,

    Due to the specifics of the Silverlight's dependency properties, there is are two cases when the SelectedItem will point to the newly selected item when the SelectionChanging event is fired. The first case is when the SelectedItem property is set programmatically. The second case is when the SelectedItem is set via binding. If you select an item by tapping on a visual container in the RadDataBoundListBox control, the SelectionChanging event will be fired prior the initialization of the SelectedItem property.

    This is implied because we cannot hook and validate the input when setting the SelectedItem property via binding or programmatically and thus prevent it from being initialized with a value that might be canceled upon the SelectionChanging event.

    I hope this explains the case.

    Do not hesitate to get back to us in case you have further questions or need assistance.

    All the best,
    Deyan
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. DevCraft banner
  4. Fredrik
    Fredrik avatar
    54 posts
    Member since:
    Sep 2010

    Posted 14 Jun 2011 Link to this post

    Hi Deyan !!!

    Thanks for your answer....
    I´m trying to implement a custom TemplateSelector.
    What I need is a way to set back my current selected row to my normaltemplate from my "selected template" when tapping on a new row.
    If I cant use the SelectionChanging event how can I do this?
    I'm using the ItemTap event for setting my "selected template" for a row.

    Regards

    Fredrik
  5. Answer
    Deyan
    Admin
    Deyan avatar
    2037 posts

    Posted 14 Jun 2011 Link to this post

    Hi Fredrik,

    Thanks for writing back.

    You still could use the SelectionChanging event and access the previous selected item from the event arguments. Take a look at the code snippet below:

    void listBox_SelectionChanging(object sender, SelectionChangingEventArgs e)
    {
        if (e.RemovedItems.Count > 0)
        {
            object oldItem = e.RemovedItems[0];
            RadDataBoundListBoxItem visualContainer = this.listBox.GetContainerForItem(oldItem) as RadDataBoundListBoxItem;
            if (visualContainer != null)
            {
                //TODO: set normal template of old selected item
            }
        }
    }

    I hope this helps.

    Do not hesitate to get back to us in case you have further questions or need assistance.

    Kind regards,
    Deyan
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  6. Fredrik
    Fredrik avatar
    54 posts
    Member since:
    Sep 2010

    Posted 14 Jun 2011 Link to this post

    Hi !!!

    That solved the problem.
    Excellent support on telerik....credits to you guys.

    Regards

    Fredrik
Back to Top
DevCraft banner