Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh KumarRank #91 · 22.9K reputationPosted Mar 10, 2023, 6:16 AM EST
Hello Darshit,
Your are doing right but just missed to add your combobox column to add,
houseNameDataGridViewComboBoxColumn.DataSource = dtGetHouse; houseNameDataGridViewComboBoxColumn.ValueMember = "HouseID"; houseNameDataGridViewComboBoxColumn.DisplayMember = "HouseName"; houseNameDataGridViewComboBoxColumn.DataPropertyName = "HouseID" houseNameDataGridView.Columns.Add(houseNameDataGridViewComboBoxColumn); // houseNameDataGridView this one is your datagridview nameNaimish MakwanaRank #324 · 7.7K reputationPosted Mar 10, 2023, 4:42 AM EST
Hello Darshit ,
What error you are getting?
Thanks
Naimish Makwana
Darshit Kalaigar45 reputationPosted Mar 10, 2023, 5:37 AM EST
I am displaying Students House in DataGridView ComboBox Column. So when i m Selecting any of the value, it displays its "id" and not "name".
Thanks
Naimish MakwanaRank #324 · 7.7K reputationPosted Mar 10, 2023, 5:48 AM EST
Hello Darshit,
If you are displaying the students' houses in a
DataGridViewComboBoxColumnand it is displaying the ID instead of the name when you select a value, it means that theValueMemberproperty is set to the column in the data source that contains the ID, instead of the column that contains the name.try like below:
// Assuming you have a DataGridView called dataGridView1 and a data source called dataSource // that contains the list of students and their houses. // Create a new DataGridViewComboBoxColumn DataGridViewComboBoxColumn column = new DataGridViewComboBoxColumn(); // Set the name of the column column.Name = "House"; // Set the data source for the column column.DataSource = dataSource; // Set the display member to the column that contains the house name column.DisplayMember = "HouseName"; // Set the value member to the column that contains the house ID column.ValueMember = "HouseID"; // Add the column to the DataGridView dataGridView1.Columns.Add(column);Thanks
Naimish Makwana
Darshit Kalaigar45 reputationPosted Mar 10, 2023, 5:53 AM EST
Hello Naimishbhai,
I already used it but it's not working. & also tried this.
houseNameDataGridViewComboBoxColumn.DataSource = dtGetHouse;
houseNameDataGridViewComboBoxColumn.ValueMember = "HouseID";
houseNameDataGridViewComboBoxColumn.DisplayMember = "HouseName";
houseNameDataGridViewComboBoxColumn.DataPropertyName = "HouseID"
Naimish MakwanaRank #324 · 7.7K reputationPosted Mar 10, 2023, 5:59 AM EST
Check this link. It might help you.
https://stackoverflow.com/questions/30384684/cells-show-the-value-member-id-instead-display-member
Darshit Kalaigar45 reputationPosted Mar 10, 2023, 6:42 AM EST
Hello Jigneshbhai,
Already did in Designing.
Thanks