日期:2014-05-17  浏览次数:20728 次

为什么这个combox它没有显示在我想的位置上,为什么它要乱跑
想datagridview里边实现下拉框来选择,就少输入些
但是。。。。

代码如下,从网上看来的

                        ComboBox cbb = new ComboBox();
                        cbb.Items.AddRange(new String[] { "Beijing", "Shanghai", "Guangzhou", "Wuhan", "Shenzhen" });
                        DataGridViewCell dgvc = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
                        Rectangle rect = this.dataGridView1.GetCellDisplayRectangle(dgvc.ColumnIndex, dgvc.RowIndex, true);
                        //cbb.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)));
                        cbb.Location = rect.Location;
                        cbb.Size = rect.Size;
                        this.Controls.Add(cbb);
                        cbb.Visible = true;

可是运行了,却出现了

这个combox怎么就会乱跑呢
查了下,两个的location
cbb是combox
rect是datagridview 里的cell

------解决方案--------------------
this.dataGridView1.Controls.Add(cbb);