We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Binding SelectedItems on Multiple selection throws exception

Thread ID:

Created:

Updated:

Platform:

Replies:

132970 Oct 1,2017 07:07 PM Apr 24,2018 11:51 AM Xamarin.Forms 3
loading
Tags: SfListView
Emil
Asked On October 1, 2017 07:07 PM

I am using MVVM and trying to bind slecteditems twoway mode. If I bind selecteditems from Viewmodel to View by raising Property changed, It throws exception as below

  <sfListView:SfListView x:Name="listItems"   SelectedItems="{Binding SelectedItems, Mode=TwoWay}"                 
                           ItemsSource="{Binding Items}"  SelectedItem="{Binding SelectedItem, Mode=OneWayToSource}"             
                             SwipeOffset="250"  BackgroundColor="White" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
                          SelectionMode="Multiple"  
                                           ItemSpacing="1"  IsStickyHeader="False" IsStickyFooter="False"   
                   AllowSwiping="True" IsEnabled="True">



  private ObservableCollection<Database.Model.Item> selectedItems;

        public ObservableCollection<Database.Model.Item> SelectedItems
        {
            get
            { 
                return selectedItems;
            }
            set
            {
                if (value != selectedItems && ListSelectionMode == SelectionMode.Multiple)
                {
                    selectedItems = value;
                    RaisePropertyChanged("SelectedItems");
                }
            }
        }



10-02 00:55:08.832 I/MonoDroid(24942): System.NullReferenceException: Object reference not set to an instance of an object.
10-02 00:55:08.832 I/MonoDroid(24942):   at Syncfusion.ListView.XForms.SfListView.OnSelectionModeChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x00015] in <eb04770f88c84a24bd134736ce89a543>:0 
10-02 00:55:08.832 I/MonoDroid(24942):   at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.BindableObject+SetValueFlags attributes, System.Boolean silent) [0x00108] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:592 
10-02 00:55:08.832 I/MonoDroid(24942):   at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.BindableObject+SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x0015b] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:386 
10-02 00:55:08.832 I/MonoDroid(24942):   at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x001f9] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindingExpression.cs:173 
10-02 00:55:08.832 I/MonoDroid(24942):   at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindingExpression.cs:55 
10-02 00:55:08.832 I/MonoDroid(24942):   at Xamarin.Forms.BindingExpression+BindingExpressionPart.<PropertyChanged>b__47_0 () [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindingExpression.cs:539 
10-02 00:55:08.832 I/MonoDroid(24942):   at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <d278c06ad5684d6882c743a94a93ebc2>:0 
10-02 00:55:08.832 I/MonoDroid(24942):   at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <d278c06ad5684d6882c743a94a93ebc2>:0 
10-02 00:55:08.832 I/MonoDroid(24942):   at (wrapper dynamic-method) System.Object:69d2077b-b265-45f9-a8c2-7c7704266070 (intptr,intptr)
 

Dinesh Babu Yadav [Syncfusion]
Replied On October 2, 2017 06:44 AM

Hi Emil,   
     
Sorry for the inconvenience caused.     
    
Based on the given information, we have checked the reported issue and a support incident has been created under your account to track the status of the issue. Please log on to our support website to check for further updates.          
    
    
Regards,    
Dinesh Babu Yadav 


Damian
Replied On April 23, 2018 12:08 PM

Hello,

Same issue today. Can we bind to SelectedItems?
Property SelectedItems has only getter. 
Syncfusion: this control is great! You doing well:) but can you provide usage of SelectedItems in MVVM manner?  

Damian

This code throw exception:

 
                    x:Name="Vendors"
                    ItemsSource="{Binding Vendors}" SelectionMode="Multiple"
                    SelectedItems="{Binding SelectedVendors}"
                    SelectionChanged="SfListView_SelectionChanged"
                    VerticalOptions="Start" Orientation="Horizontal">

[0:] System.NullReferenceException: Object reference not set to an instance of an object.
  at Syncfusion.ListView.XForms.SelectionController.ProcessItemsSourceChanged (System.Object oldValue, System.Object newValue) [0x00040] in :0 
  at Syncfusion.ListView.XForms.SfListView.OnItemsSourceChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x0001d] in :0 

Rawoof Sharief Muthuja Sherif [Syncfusion]
Replied On April 24, 2018 11:51 AM

Hi Damian, 
 
We have checked the reported query “Binding collection of items to SelectedItems property throws null reference exception” from our side. We would like to let you know that SelectedItems property uses ObservableCollection of type ‘object’. So you need to specify generic object instead of model class as like below. 
 
Code Example[C#]: 
        private ObservableCollection<object> selectedItems; 
 
        public ObservableCollection<object> SelectedItems 
        { 
            get 
            { 
                return selectedItems; 
            } 
            set 
            { 
                if (value != selectedItems && ListSelectionMode == SelectionMode.Multiple) 
                { 
                    selectedItems = value; 
                    RaisePropertyChanged("SelectedItems"); 
                } 
            } 
        } 
  
Please let us know if you require further assistance. 
 
Regards, 
Rawoof.M 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;