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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Can sfComboBox use named tuples for value and display members ?

Thread ID:

Created:

Updated:

Platform:

Replies:

149011 Nov 11,2019 07:00 AM UTC Nov 18,2019 05:09 AM UTC WPF 3
loading
Tags: ComboBoxAdv
ios man
Asked On November 11, 2019 07:00 AM UTC

Hello,


A sfComboBox with a SortedSet of named tuples will throw an exception when .ValueMember and .DisplayMember set.

Designer settings
  • DropDownStyle is DropDownList
  • AllowSelectAll is true
  • ComboBoxMode is MultiSelection
The following will throw an Exception "System.NullReferenceException: 'Object reference not set to an instance of an object.'
" when the drop down list opened by user.

Dates = new SortedSet<(DateTime val,string show)>();
DateTime dt;
dt = DateTime.Parse("01/01/2019 12:00:00"); Dates.Add((val: dt, show: dt.ToString("D")));
dt = DateTime.Parse("02/01/2019 12:00:00"); Dates.Add((val: dt, show: dt.ToString("D")));
dt = DateTime.Parse("01/15/2019 12:00:00"); Dates.Add((val: dt, show: dt.ToString("D")));

sf_comboBox1.DataSource = Dates;
sf_comboBox1.ValueMember = "val";
sf_comboBox1.DisplayMember = "show";

When the member settings are not assigned, the drop down list shows check boxes with the tuple rendering (without names)

☐ Select All
☐ (01/01/2019 12:00:00 PM, Tuesday, January 1, 2019)
☐ (01/15/2019 12:00:00 PM, Tuesday, January 15, 2019)
☐ (02/01/2019 12:00:00 PM, Friday, February, 2019)
      
What I want in the drop down list is just the "D" formatted datetime without parenthesis


thanks
iosman

Vijayalakshmi Roopkumar [Syncfusion]
Replied On November 12, 2019 12:12 PM UTC

Hi iosman

Thank you for your patience.

In our Syncfusion SfComboBox control, there is no SortedSet feature .So when we bind the datasource with DisplayMember and ValueMember property, it will throw the null exception. You can restrict this NRE crash using the following code:

Code Example:[C#]

 
 
  
sfComboBox1.DataSource = Dates.Select(x => x.show).ToList();   
  
 

We have also attached the sample for your reference below:

Samplehttps://www.syncfusion.com/downloads/support/directtrac/149011/ze/SfComboBox-1200953919
 

Please try this solution and let us know if it is helpful for you.

Regards
Vijayalakshmi V.R. 
 


ios man
Replied On November 16, 2019 06:22 AM UTC

Hello,


A sfComboBox with a SortedSet of named tuples will throw an exception when .ValueMember and .DisplayMember set.

Designer settings
  • DropDownStyle is DropDownList
  • AllowSelectAll is true
  • ComboBoxMode is MultiSelection
The following will throw an Exception "System.NullReferenceException: 'Object reference not set to an instance of an object.'
" when the drop down list opened by user.

Dates = new SortedSet<(DateTime val,string show)>();
DateTime dt;
dt = DateTime.Parse("01/01/2019 12:00:00"); Dates.Add((val: dt, show: dt.ToString("D")));
dt = DateTime.Parse("02/01/2019 12:00:00"); Dates.Add((val: dt, show: dt.ToString("D")));
dt = DateTime.Parse("01/15/2019 12:00:00"); Dates.Add((val: dt, show: dt.ToString("D")));

sf_comboBox1.DataSource = Dates;
sf_comboBox1.ValueMember = "val";
sf_comboBox1.DisplayMember = "show";

When the member settings are not assigned, the drop down list shows check boxes with the tuple rendering (without names)

☐ Select All
☐ (01/01/2019 12:00:00 PM, Tuesday, January 1, 2019)
☐ (01/15/2019 12:00:00 PM, Tuesday, January 15, 2019)
☐ (02/01/2019 12:00:00 PM, Friday, February, 2019)
      
What I want in the drop down list is just the "D" formatted datetime without parenthesis


thanks
iosman

thanks my issue has been fixed ...







Vijayalakshmi Roopkumar [Syncfusion]
Replied On November 18, 2019 05:09 AM UTC

Hi ios,

Thank you for your update.

We are glad to hear that your problem with SfComboBox has been solved by our solution.

Please let us know if you need any further assistance on this.

Regards
Vijayalakshmi V.R.

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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon