Thursday, 18 October 2012

how to add combobox in dataGridView windows c#.net

 dataGridView1.ColumnCount = 2;
            dataGridView1.Columns[0].Name = "EID";
            dataGridView1.Columns[1].Name = "NAME";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string[] r = new string[] { dt.Rows[i].ItemArray[0].ToString(), dt.Rows[i].ItemArray[1].ToString() };
                dataGridView1.Rows.Add(r);
            }
            DataGridViewComboBoxColumn dgc = new DataGridViewComboBoxColumn();
            //dgc.DataSource = dt1;
            //dgc.DisplayMember = "DNAME";
            //dgc.ValueMember = "DID";

            dgc.HeaderText = "Department";
            for (int i = 0; i < dt1.Rows.Count; i++)
            {
                dgc.Items.Add(dt1.Rows[i].ItemArray[1].ToString());
            }
            dataGridView1.Columns.Add(dgc);

No comments:

Post a Comment