我如何在datagridview列中实现combobox?

时间:2013-09-06 05:32:57

标签: .net winforms datagridview combobox ado.net

我想用Combobox Column构建一个datagridview,用户在db / dataset / datatable中输入要搜索的值。用户输入3个字符/数字后,搜索过程开始。我怎么能这样做?

            for (int i = 0; i < dataGridView2.Rows.Count; i++)
            {
                    ComboBox comboBoxHeaderCell = new ComboBox();
                    int xPos = dataGridView2.Width;
                    xPos -= dataGridView2.Rows[i].Cells[1].Size.Width;
                    dataGridView2.Controls.Add(comboBoxHeaderCell);
                    comboBoxHeaderCell.Size = dataGridView2.Columns[0].HeaderCell.Size;
                    comboBoxHeaderCell.Location = new Point(xPos, 0);
                    comboBoxHeaderCell.Location = dataGridView2.GetCellDisplayRectangle(i, 0, true).Location;
                    xPos += comboBoxHeaderCell.Size.Width;
                    //comboBoxHeaderCell.DataSource=dtusers2;
                    //comboBoxHeaderCell.ValueMember = "Name1";
                    //comboBoxHeaderCell.DisplayMember = "Name2";
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            comboBoxHeaderCell.Items.Add(dr[0].ToString());
                        }
                        c++;
                    }
               // }

            }

通过此代码,只有一个组合框在(0,0)位置生成。但我希望它在第1列的所有行中。

0 个答案:

没有答案