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

Can sfComboBox use named tuples for value and display members ?

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

3 Replies

MJ Mythily Jega Jothi Syncfusion Team September 2, 2019 01:12 PM UTC

Hi Richard,

Thank you for contacting Syncfusion Support.

We are able to reproduce the reported Null Reference Exception  when set  DisplayMember and ValueMember. We have considered this as defect and logged a defect report. We will provide you the patch for this fix on September 16, 2019 . We will update the feedback link for the reported problem on tomorrow ( September 3, 2019).

Please let us know if you require further assistance.

Mythily J


ON Olety Nikhilesh Olety Nagendra Syncfusion Team September 4, 2019 01:36 PM UTC

Hi Richard, 
Thank you for your patience. 
You can track the status of this report through the following feedback link, 
Nikhilesh O 

VR Vijayalakshmi Roopkumar Syncfusion Team September 17, 2019 07:23 AM UTC

 Hi Richard

Thank you for your patience.

In our syncfusion SfComboBox control, we didn't implement the 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 followingc code:

Code Example:

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

We have also attached the sample for your reference below:

Sample: https://www.syncfusion.com/downloads/support/forum/147098/ze/SfComboBox-117117267

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

Vijayalakshmi V.R.

Live Chat Icon For mobile
Up arrow icon