Code Q & A
  • index
  • Java
  • python
  • javascript
No Result
View All Result
Code Q & A
  • index
  • Java
  • python
  • javascript
No Result
View All Result
Code Q & A
No Result
View All Result

Exception when setting SelectedValue on CF Combobox

06/23/2022
in combobox, compact-framework, selectedvalue
Reading Time: 1 min read

I am using Compact Framework 3.5 and have the following code:

var timeouts = new[] {1, 2, 3, 4, 5};
ddlTimeout.DataSource = timeouts;
ddlTimeout.SelectedValue = 3;

And receive the following error on setting selected value. Where's an issue?

Cannot set the SelectedValue in a ListControl with an empty ValueMember

Note: It works well if I use List<> of class objects as DataSource with specifying DisplayMember and ValueMember for the ComboBox.

The error is

"Cannot set the SelectedValue in a ListControl with an empty
ValueMember."

Try this instead:

var timeouts = new[] {1, 2, 3, 4, 5};
ddlTimeout.DataSource = timeouts;
ddlTimeout.SelectedItem = 3;

You have to have the ValueMember set for SelectedValue to work. The documentation shows the difference:

ComboBox.SelectedValue Gets or sets the value of the member property specified by the ValueMember property

ComboBox.SelectedItem Gets or sets currently selected item in the ComboBox.

Tags: comboboxcompact-frameworkselectedvalue
ShareTweetPin

Related Posts

c#

How do I have an enum bound combobox with custom string formatting for enum values?

In the post Enum HowNice { ReallyNice, SortOfNice, NotNice } And then, you call a function GetDescription, using syntax like:...

combobox

Linq-to-sql Null value not displayed in combobox bound to FK

I've a combobox that is binded to a FK entity (the object, not the ID-field). The combobox is filled with...

c#

ComboBox DataBinding C# WinForms

I have 2 Tables: Diagnose: ID, Name DiagnoseForPatients: PatientID, DiagnoseID. I have A DateGridView with 2 ComboBoxes: First ComboBox needs...

c#

Combobox binding does not update

I'm trying to bind a combobox to a value in data set I navigate through using a binding navigator. I...

Next Post

C# New Row, BindingSource, DataGridView

Hot tags

.htaccess .net Algorithm amazon-web-services android Apache c# css c语言 django django-models docker google-app-engine google-cloud-platform hadoop Hive html ios java javascript kubernetes linux macos maven mysql node.js php postgresql python python-2-7 Python 3.X R ruby ruby-on-rails spring SQL SQL SERVER svn TensorFlow ubuntu windows xcode 爬虫 算法 编程语言

    © 2022 Websitedic.com.

    No Result
    View All Result
    • index
    • Java
    • python
    • javascript