Hello,
I am quite new to C# and I am trying to populate fill several textboxes with data from a selected combobox.
I have my main window with the textboxes and comboboxes and a separate class for the connection to the database (I am using XAMPP/PhpMyAdmin).
I managed to fill the comboboxes with the data from the database, but I cannot fill the texboxes from the selected combobox.
I checked other questions and tutorials, but all I managed to achieve is to get the primary key into the text box, but I need different columns from the table, depending on the textbox.
What I have tried:
I populated the combobox from the database:
void Completez_Combo_Furnizor()
{
combo_furnizor = DB_Furnizori.Combo_Furnizor();
comboBoxFurnizor.Items.Clear();
comboBoxFurnizor.DataSource = combo_furnizor;
comboBoxFurnizor.ValueMember = "id_furnizor";
comboBoxFurnizor.DisplayMember = "nume";
}
I double clicked on the combobox and wrote the following, but all I can get is the primary key (the first column). In the textbox, I need to get the 7th column (which is a double type.
private void comboBoxFurnizor_SelectedIndexChanged(object sender, EventArgs e)
{
textBoxPret.Text = comboBoxFurnizor.SelectedItem.ToString();
}
And this is from the database class (DB_Furnizori.cs), where I open the connection and have multiple queries for the database.
public static DataTable Combo_Furnizor()
{
conn.Open();
MySqlCommand comboFurnizor = new MySqlCommand("SELECT * from furnizori ORDER BY nume", conn);
MySqlDataAdapter adaptc = new MySqlDataAdapter(comboFurnizor);
DataTable combo_furnizori = new DataTable();
adaptc.Fill(combo_furnizori);
conn.Close();
return combo_furnizori;
}
Please help, I don't know how to make it work :(