Home > DeveloperSection > Blogs > combobox in datagridview

combobox in datagridview


C# C# 
Ratings:
0 Comment(s)
 1621  View(s)
Rate this:
 private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            ComboBox editingComboBox = (ComboBox)e.Control;
            if (editingComboBox != null)
                editingComboBox.SelectedIndexChanged += new System.EventHandler(this.editingComboBox_SelectedIndexChanged);
        }
        private void editingComboBox_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            ComboBox comboBox1 = (ComboBox)sender;
            // Display index
            //MessageBox.Show(comboBox1.SelectedIndex.ToString());
            // Display value
            SqlDataAdapter adp = new SqlDataAdapter("select edd from cdl where id='" + comboBox1.SelectedValue.ToString() + "'", con);
            DataTable dt = new DataTable();
            adp.Fill(dt);
 
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ED.DataSource = dt;
                ED.DisplayMember = dt.Rows[i]["edd"].ToString();
                ED.ValueMember = dt.Rows[i]["edd"].ToString();
               
            }

        }
            //MessageBox.Show(comboBox1.Text);

I am writing this code but doesnot work wats problem pls help me...@@

Don't want to miss updates? Please click the below button!

Follow MindStick