There is problem with combo box values when I double-click on row of data grid view the values from the row passes to text boxes correctly but with combobox there is problem the value is not same in combobox as in data gridview row let me show you in picture.
Used code
For Textbox:
ar.txtcity.Text = this.dataGridView1.CurrentRow.Cells[5].Value.ToString();
For Combobox:
combobox ar.txtcombo.Text = this.dataGridView1.CurrentRow.Cells[6].Value.ToString();
Try this one.
ar.txtcombo.SelectedIndex = ar.txtcombo.FindString(
this.dataGridView1.CurrentRow.Cells[6].Value.ToString());
I think it will help :)
int class= int.Parse(row.Cells[6].Value.ToString());
NameOfYourComboBox.SelectedValue = class;
if the value is not in the database, you can use this;
NameOfYourComboBox.Text = row.Cells[6].Value.ToString();
I have tried this many times and it has worked fine for me with WinForms
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.