Morning all
In my student administration app I had some comboboxes where the display member and the value member differed so I used the following code which seems to work fine
What I am struggling with is the following
When the student profile gets edited I need the combobox item that was written to the database to be automatically selected.
I tried using selected value and it doesn't give an error but doesn't give the expected results. I tried using valuemember but I get a "Cannot bind to the new value member.
Parameter name: value" error
Enjoy your day everyone
In my student administration app I had some comboboxes where the display member and the value member differed so I used the following code which seems to work fine
C#:
// ### populate combobox for Remembering Rating Code ###
// Create a List to store our KeyValuePairs
string QueryRememberingRatingCode = @"select HFRatingId, HFRatingDescription from HealthFunctioning";
SqlCommand cmdRememberingRatingCode = new SqlCommand(QueryRememberingRatingCode, conn);
List<KeyValuePair<string, string>> RememberingRatingData = new List<KeyValuePair<string, string>>();
SqlDataReader rdrRememberingRatingCode = cmdRememberingRatingCode.ExecuteReader();
//// Loop through the result set
while (rdrRememberingRatingCode.Read())
{
RememberingRatingData.Add(new KeyValuePair<string, string>(rdrRememberingRatingCode["HFRatingId"].ToString(), rdrRememberingRatingCode["HFRatingDescription"].ToString()));
}
// Clear the comboBox
cboRememberingRatingCode.DataSource = null;
cboRememberingRatingCode.Items.Clear();
// Bind the combobox
cboRememberingRatingCode.DataSource = new BindingSource(RememberingRatingData, null);
cboRememberingRatingCode.DisplayMember = "value";
cboRememberingRatingCode.ValueMember = "Key";
// Close home Remembering rating Code reader
rdrRememberingRatingCode.Close();
When the student profile gets edited I need the combobox item that was written to the database to be automatically selected.
I tried using selected value and it doesn't give an error but doesn't give the expected results. I tried using valuemember but I get a "Cannot bind to the new value member.
Parameter name: value" error
Enjoy your day everyone