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. Image for the cookie policy date
close icon

DataTemplateSelector in SfListView

Is it possible to have a data templateselector in the Listview, I want to be able to bind to several different data templates based from a value on the bound items, is this possible with SfListView?

Regards
Jason

8 Replies

DB Dinesh Babu Yadav Syncfusion Team February 9, 2017 04:37 AM UTC

Hi Jason, 
 
Thank you for using Syncfusion products. 
 
You can achieve your requirement “DataTemplateSelector in SfListView” and the feature “DataTemplateSelector” has been included in our Essential Studio Volume 4 SP1, 2016 (Version 14.4.0.20) release and you can download it from the below link.  
  
 
For your reference, we have attached a sample which illustrates the working with DataTemplateSelector in SfListView . Please find the sample link below. 
 
 
Please let us know if you require further assistance. 
 
Regards, 
Dinesh Babu Yadav 
 



JA Jason February 9, 2017 07:21 PM UTC

OK looks goo din theory, although if I run the demo, with latest builds of products it crashes on a iphone simulator...

at Syncfusion.ListView.XForms.iOS.ExtendedScrollViewRenderer.WillMoveToWindow (UIKit.UIWindow window) [0x00006] in <25fb134a0e484765b5209b807d9adabb>:0 
  at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSendSuper_IntPtr (intptr,intptr,intptr)
  at UIKit.UIView.AddSubview (UIKit.UIView view) [0x00041] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/build/ios/native/UIKit/UIView.g.cs:245 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x00022] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:67 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (System.Object sender, Xamarin.Forms.ElementEventArgs e) [0x0000f] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:113 
  at Xamarin.Forms.Element.OnChildAdded (Xamarin.Forms.Element child) [0x0002a] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Element.cs:353 
  at Xamarin.Forms.VisualElement.OnChildAdded (Xamarin.Forms.Element child) [0x00000] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:570 
  at Xamarin.Forms.Layout`1[T].OnChildAdded (Xamarin.Forms.Element child) [0x00000] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:31 
  at Xamarin.Forms.Layout.OnInternalAdded (Xamarin.Forms.View view) [0x0001d] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:402 
  at Xamarin.Forms.Layout.InternalChildrenOnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00089] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:392 
  at (wrapper delegate-invoke) <Module>:invoke_void_object_NotifyCollectionChangedEventArgs (object,System.Collections.Specialized.NotifyCollectionChangedEventArgs)
  at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00012] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:288 
  at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index) [0x00000] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:351 
  at System.Collections.ObjectModel.ObservableCollection`1[T].InsertItem (System.Int32 index, T item) [0x00024] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:219 
  at System.Collections.ObjectModel.Collection`1[T].Add (T item) [0x00023] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/collections/objectmodel/collection.cs:67 
  at Xamarin.Forms.ObservableWrapper`2[TTrack,TRestrict].Add (TRestrict item) [0x0004b] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\ObservableWrapper.cs:35 
  at Syncfusion.ListView.XForms.SfListView.OnSizeAllocated (System.Double width, System.Double height) [0x0003c] in <b39610c542884f1593890d35a0654fb6>:0 
  at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:629 
  at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:773 
  at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:157 
  at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:511 
  at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x0016b] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:148 
  at Xamarin.Forms.Grid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00144] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\GridCalc.cs:48 
  at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x000c7] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:229 
  at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:194 
  at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:629 
  at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:773 
  at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:157 
  at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:511 
  at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x0016b] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:148 
  at Xamarin.Forms.Page.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00111] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Page.cs:182 
  at Xamarin.Forms.Page.UpdateChildrenLayout () [0x000d0] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Page.cs:255 
  at Xamarin.Forms.Page.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Page.cs:236 
  at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:629 
  at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:773 
  at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:157 
  at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:511 
  at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x0000a] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:120 
  at Xamarin.Forms.Page.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00111] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Page.cs:182 
  at Xamarin.Forms.Page.UpdateChildrenLayout () [0x000d0] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Page.cs:255 
  at Xamarin.Forms.Page.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Page.cs:236 
  at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:629 
  at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:773 
  at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:157 
  at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:511 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.ViewDidLayoutSubviews () [0x0011e] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:165 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/UIKit/UIApplication.cs:63 
  at DataTemplateSelector.iOS.Application.Main (System.String[] args) [0x00008] in /Users/Jason/Downloads/DataTemplateSelector/DataTemplateSelector/DataTemplateSelector.iOS/Main.cs:17 


DB Dinesh Babu Yadav Syncfusion Team February 10, 2017 04:32 PM UTC

Hi Jason,    
    
Sorry for the inconvenience caused.    
    
The reported issue “Null reference exception throws when SfListView is loaded in NavigationPage in iOS platform” has been resolved at our end and the fix for the issue will be included in our upcoming 2017 Vol 1 release which is scheduled to be rolled out by the mid of this month.     
         
Please let us know if you require further assistance.    
    
Regards,    
Dinesh Babu Yadav 



DB Dinesh Babu Yadav Syncfusion Team February 14, 2017 11:36 AM UTC

Hi Jason,   
   
The fix for the reported issue “Null reference exception throws when SfListView is loaded in NavigationPage in iOS platform” has been included in this release. Also we are glad to announce that our Essential Studio 2017 Volume 1 Main Release v15.1.0.33 is rolled out and is available for download under the following link.   
   
   
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.   
   
Regards               
Dinesh Babu Yadav 



JA Jason February 14, 2017 08:05 PM UTC

Hi there,

Thank you for letting me know, I have installed the latest build and have been able to successfully use the data templateselector in the SfListView in IOS.

Thank you again!
Jason 


DB Dinesh Babu Yadav Syncfusion Team February 15, 2017 10:07 AM UTC

Hi Jason, 
 
Thanks for the update. 
 
Regards, 
Dinesh Babu Yadav 



LS Lloyd Sheen December 29, 2021 10:46 PM UTC

Another response that is (well I have to be somewhat rude) screwed.  There is no  DataTemplateSelector property in the SfListView so everything in this post is wr



LN Lakshmi Natarajan Syncfusion Team December 30, 2021 09:04 AM UTC

Hi Lloyd, 
 
The SfListView allows customizing appearance of each item with different templates based on specific constraints by using the DataTemplateSelector. 
 
We have user guidance document for the same and you can refer from the following link, 
 
Lakshmi Natarajan 
 


Loader.
Live Chat Icon For mobile
Up arrow icon