On my main form, there’s dataGridView1 and it’s bound to a database table. On my edit form, there’s a ComboBox which gets it’s items via Data Binding to the column from the same database as dataGridView1. On dataGridView1 cell double click, that edit form opens and populates all the fields needed for editing that certain line.
Here’s my problem:
When I try to set the value of ComboBox on that edit form, nothing happens. No error is given and the item in ComboBox is not selected.
fDodaj nov = new fDodaj();
nov.comboBox1.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[4].Value.ToString();
if(nov.ShowDialog()==DialogResult.OK)
{
//code that updates the value in database
}
fDodaj is my editing form.
I’ve tryed setting SelectedValue, SelectedItem, SelectedText and Text properties on ComboBox, no luck in any case.
What am I doing wrong?
PS: I’m not very goot at Visual C#, but this is for my school project. If you need any more info, just let me know.
Move your ComboBox data binding into the constructor of your form, rather than keeping it in the Form.Load as you’re currently doing. Ensure that it is bound after the call to
InitializeComponentin your constructor.This will allow you to set the ComboBox SelectedValue or similar before the dialog is shown.