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

is not attachable to type elements of type 'RadGridView'

4 Answers 137 Views
GridView
This is a migrated thread and some comments may be shown as answers.
ken
Top achievements
Rank 1
ken asked on 29 Mar 2011, 09:21 PM
Hi there,

I have a custom MultiSelect attached property, I can use it with a ListBox however I can't seem to use it with your grid view, I get an error that say's property 'IsEnabled' is not attachable to type elements of type 'RadGridView' - Why would it work with a listbox but not a gridview? I mean, it's just an attached property - I don't see what the issue is with a the grid.

Here is the code for the MultiSelect.cs
public static class MultiSelect
  {
      static MultiSelect()
      {
          Selector.ItemsSourceProperty.OverrideMetadata(typeof(Selector), new FrameworkPropertyMetadata(ItemsSourceChanged));
      }
 
      public static bool GetIsEnabled(Selector target)
      {
          return (bool)target.GetValue(IsEnabledProperty);
      }
 
      public static void SetIsEnabled(Selector target, bool value)
      {
          target.SetValue(IsEnabledProperty, value);
      }
 
      public static readonly DependencyProperty IsEnabledProperty =
          DependencyProperty.RegisterAttached("IsEnabled", typeof(bool), typeof(MultiSelect),
              new UIPropertyMetadata(IsEnabledChanged));
 
      static void IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
      {
          Selector selector = sender as Selector;
          IMultiSelectCollectionView collectionView = selector.ItemsSource as IMultiSelectCollectionView;
 
          if (selector != null && collectionView != null)
          {
              if ((bool)e.NewValue)
              {
                  collectionView.AddControl(selector);
              }
              else
              {
                  collectionView.RemoveControl(selector);
              }
          }
      }
 
      static void ItemsSourceChanged(object sender, DependencyPropertyChangedEventArgs e)
      {
          Selector selector = sender as Selector;
 
          if (GetIsEnabled(selector))
          {
              IMultiSelectCollectionView oldCollectionView = e.OldValue as IMultiSelectCollectionView;
              IMultiSelectCollectionView newCollectionView = e.NewValue as IMultiSelectCollectionView;
 
              if (oldCollectionView != null)
              {
                  oldCollectionView.RemoveControl(selector);
              }
 
              if (newCollectionView != null)
              {
                  newCollectionView.AddControl(selector);
              }
          }
      }
  }
Thanks for any help...

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 30 Mar 2011, 06:57 AM
Hello,

 This class is written for Selector control types like plain ListBox - RadGridView is not Selector. If you want to enable multiple rows selection please visit our selection demos for more info. 

Regards,
Vlad
the Telerik team
0
ken
Top achievements
Rank 1
answered on 30 Mar 2011, 02:03 PM
Darn, I forgot to mention, this is MVVM, so of can't say gridview.selectIems or gridview.clear() or whatever... I need to somehow let my view model know about the selected items. I looked at the demos but they appear to be using the code behind files for the xaml pages which doesn't help me.

Thanks
0
Vlad
Telerik team
answered on 30 Mar 2011, 02:07 PM
Hi,

 You can check also this blog post for more info about selection, binding, MVVM, etc. 

Best wishes,
Vlad
the Telerik team
0
ken
Top achievements
Rank 1
answered on 30 Mar 2011, 02:10 PM
Yeah - I wanted to avoid using a behavior but at this point I don't care... If it works I will be happy. :)
Tags
GridView
Asked by
ken
Top achievements
Rank 1
Answers by
Vlad
Telerik team
ken
Top achievements
Rank 1
Share this question
or