justanidiot
justanidiot

Reputation: 21

datamember property 'System' cannot be found on the DataSource

I am binding a Dictionary to a ComboBox. This seems to work alright without any compile errors, but at runtime I get the error:

datamember property 'System' cannot be found on the DataSource

Here is my code:

public Dictionary<string, object> valuList
{
  set
  {
    lComboBox.DataSource = new BindingSource(value,null);
    lComboBox.DisplayMember = (value.Keys).ToString();
    lComboBox.ValueMember = (value.Values).ToString();
  }
}

Dictionary<string, string> x6 = new Dictionary<string, string>();
x6.Add("AS", "ASS");
x6.Add("AAS", "AASS");
myForm.valuList = x6;

Upvotes: 0

Views: 1328

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500903

If you want the display member to be the key of each pair in the dictionary, and the value member to be the value of each pair, you probably want:

lComboBox.DisplayMember = "Key";
lComboBox.ValueMember = "Value";

You should be aware that the order will be undetermined though - is that really what you want?

Calling ToString() on the return value of Dictionary<,>.Keys or Dictionary<,>.Values is probably just going to give you the fully-qualified name of a type, which will start with System.Collections... - that's why you're getting the current error.

I'd also strongly encourage you to rename your property to something which follows the .NET naming conventions, and also means something.

Upvotes: 1

Related Questions