Hello friend
as per your question's need
you have to do three things as below.....
1st just make a method that load data from DB to comb box.
private void GetColumnOnComboBox()
{
try
{
SqlConnection ObjConnection = new SqlConnection();
ObjConnection.ConnectionString = ConfigurationSettings.AppSettings["constring"];
ObjConnection.Open();
string str = "select ColumnName from TableName";
SqlDataAdapter da = new SqlDataAdapter(str, ObjConnection);
DataSet ds = new DataSet();
da.Fill(ds, "YourTableName");
this.comboBox1.DataSource = ds.Tables["ProductMaster"];
this.comboBox1.DisplayMember = "ColumnName";
this.comboBox1.ValueMember = "ColumnName";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally { ObjConnection.Close(); }
}
2nd now pass this method on form load event................
private void form1_Load(object sender, EventArgs e)
{
GetColumnOnComboBox();
}
3rd on comboBox SelectedIndexChanged event you have to fill text box from database with where clause of selected text of Combo Box.....like
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection ObjConnection = new SqlConnection();
ObjConnection.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["constring"];
ObjConnection.Open();
string str = "select * from YourTableName where columnName='"+ComboBox.text+"'";
SqlCommand cmd = new SqlCommand(str, ObjConnection);
SqlDataReader dr=cmd.ExecuteReader();
if(dr.Read())
{
textbox1.Text=dr["ColumnName"].ToString());
}
}
Its Simple but if any problem feel free to ask.....
Happy to help