hello brothers
i want to Fill textbox inside a DataGridView with data form database depended on selected value from combobox inside the DataGridView
this is the code for filling the cobobox
private void create_report_Load(object sender, EventArgs e)
{
SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["lap_appConnectionString"].ConnectionString);
SqlCommand objCmd = new SqlCommand("SELECT * FROM [testing_name];", objCon);
SqlDataAdapter objDA = new SqlDataAdapter(objCmd);
objDA.SelectCommand.CommandText = objCmd.CommandText.ToString();
DataTable dt = new DataTable();
objDA.Fill(dt);
Test_Name.DataSource = dt;
Test_Name.DisplayMember = "test_name";
Test_Name.ValueMember = "test_defualt_id";
}
and i try this code for filling the textbox
private void Test_Name_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection cnz = new SqlConnection(ConfigurationManager.ConnectionStrings["lap_appConnectionString"].ConnectionString);
SqlCommand cmdzs = new SqlCommand("SELECT * FROM [test_normal] WHERE test_id='" + Test_Name.Selected + "' ;", cnz);
cmdzs.CommandType = CommandType.Text;
cmdzs.Connection.Open();
SqlDataReader dr = cmdzs.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
}
}
cmdzs.Connection.Close();
}
but give me error with no property to the textbox that inside the DataGridView
this image can explain more
http://img545.imageshack.us/img545/3850/d884.png[
^]
#new_edit
i try this code
public create_report()
{
InitializeComponent();
define_gridview_columns();
add_rows();
}
public void define_gridview_columns()
{
DataGridViewComboBoxColumn test_name = new DataGridViewComboBoxColumn();
test_name.HeaderText = "Test Name";
test_name.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["lap_appConnectionString"].ConnectionString);
SqlCommand objCmd = new SqlCommand("SELECT dbo.testing_name.test_name,dbo.testing_name.test_defualt_id FROM dbo.testing_name ;", objCon);
SqlDataAdapter objDA = new SqlDataAdapter(objCmd);
objDA.SelectCommand.CommandText = objCmd.CommandText.ToString();
DataTable dt = new DataTable();
objCon.Open();
objDA.Fill(dt);
test_name.DataSource = dt;
test_name.DisplayMember = "test_name";
test_name.ValueMember = "test_defualt_id";
objCon.Close();
DataGridViewTextBoxColumn test_unit = new DataGridViewTextBoxColumn();
test_unit.HeaderText = "Normail Unit";
test_unit.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DataGridViewTextBoxColumn ref_rang = new DataGridViewTextBoxColumn();
ref_rang.HeaderText = "Reference Rang";
ref_rang.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DataGridViewTextBoxColumn new_result = new DataGridViewTextBoxColumn();
new_result.HeaderText = "New Result";
new_result.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView1.Columns.Add(test_name);
dataGridView1.Columns.Add(test_unit);
dataGridView1.Columns.Add(ref_rang);
dataGridView1.Columns.Add(new_result);
}
public void add_rows()
{
for (int i = 0; i < 10; i++)
{
dataGridView1.Rows.Add();
}
}
this create the controll that i need
and i fill the cobobox with the data that i need
now what i need is get data from the DB to the created textbox
i use this code but the property not existed for the datagridview textbos