Welcome to the Xceed Community Sign in | Join | Help
Community Search  

No change notification for SelectedItems Dependency Property

Sort Posts: Previous Next
  •  05-05-2008, 9:24 AM Post no. 11963

    No change notification for SelectedItems Dependency Property

    I posted this in another thread (http://xceed.com/CS/forums/thread/7462.aspx), but haven't received a response.  Therefore, I'll repost it here.

    I'm trying to get notification when the SelectedItems property has changed.  I'd prefer a SelectionChanged event, as Microsoft provides on their WPF ListView and on their Silverlight DataGrid.  However, it doesn't exist in the Xceed DataGrid.

     In this thread(http://xceed.com/CS/forums/thread/7462.aspx), it says I should register for change notifications for the SelectedItem Dependency property.  This works great for single selection, but not for multi-select datagrids.

     I have a DataGrid with SelectionMode set to SelectionMode.Extended.  I have registered a change notification for the SelectedItems dependency property. When selecting multiple items using the Ctrl-Shift key, no change notification event is fired, even though the SelectedItems.Count property has increased.

     Can anyone suggest a better way to do this?  Is there something wrong with the code I'm using?

     Here is my code:

    ---------------------------------------------------------------------------------------------

    DependencyPropertyDescriptor SelectedItemsChangedDescriptor =
    DependencyPropertyDescriptor.FromProperty(DataGridControl.SelectedItemsProperty,
    typeof(DataGridControl));

    SelectedItemsChangedDescriptor.AddValueChanged(myGrid,
    new EventHandler(OnSelectedItemsChanged));

    private void OnSelectedItemsChanged(object sender, EventArgs e)
    {
    // Do something with this event
    }  

    ------------------------------------------------------------------------------------------------------

  •  05-05-2008, 9:38 AM Post no. 11967 in reply to 11963

    Re: No change notification for SelectedItems Dependency Property

    Hi Todd,

       We did see your first post, but couldn't respond at the moment. Thank you for your patience.

       We noted your suggestion regarding the selection changed event. At the moment, you can receive notification regarding the selected items by using this little trick:

       INotifyCollectionChanged selectedItems = grid1.SelectedItems as INotifyCollectionChanged;

       selectedItems.CollectionChanged += myHandler;

     
     


    Marc Laroche
    Software Developer
    Xceed Software Inc.


    I don’t suffer from insanity, I enjoy every minute of it. - Unknown
    Filed under:
  •  05-05-2008, 9:44 AM Post no. 11969 in reply to 11967

    Re: No change notification for SelectedItems Dependency Property

    Thanks!  I'll give this a try.
  •  05-05-2008, 11:18 AM Post no. 11978 in reply to 11967

    Re: No change notification for SelectedItems Dependency Property

    That worked great!  Thanks again.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.