在ComboBox已经绑定数据的情况下
1.怎么样才能在ComboBox加到datagrid后使用  
Alt  +  方向键  
展开ComboBox 
2.怎么样才能在ComboBox中输入新的数据

解决方案 »

  1.   

    DataTable默认情况下ColumnStyle有文本列和是否列,可以自定义一个ComboBoxColumn我一般不用这种方式 ,这种方式虽然自定义非常灵活但是要把人搞死
    所以我一般就是在DataGrid控件的容器中加一拖一个ComboBox,单击DataGrid时我判断是否单击了要显示下拉列表的列,如果是就把数据加载到ComboBox并移到当前单元格所在位置并显示,可以设置ComboBox相应类型就可以输入数据,当它失去焦点时把数据写到单元格
      

  2.   

    private System.Windows.Forms.DataGrid.HitTestInfo hi;
    private Rectangle rc;
    if(hi.Type==DataGrid.HitTestType.Cell && hi.Column ==2)// && hi.Column !=1 ) 
    {
    rc = this.dgrdLF1.GetCellBounds(hi.Row,hi.Column);
    numEdit.Bounds = this.RectangleToClient( grid.RectangleToScreen( rc ));
    numEdit.Focus();
    numEdit.Text = grid[hi.Row,hi.Column].ToString();
    numEdit.Visible = true;
    //次函数有意思
    this.numEdit.BringToFront();
    this.btnLFOK1.Enabled = true;
    }
    else
                    numEdit.Visible = false;ComboBox是一样的思路
      

  3.   

    DataGridTextBoxColumn dgtb = (DataGridTextBoxColumn)this.dataGrid1.TableStyles[0].GridColumnStyles[2]; //这里决定哪一列是ComboBox
    ComboBox cmbFunctionArea = new ComboBox();
    //这里如果你是绑定数据到ComboBox就写数据绑定得代码
    cmbFunctionArea.Items.AddRange(new object[]{"选项一","选项二","选项三"});
    cmbFunctionArea.Cursor = Cursors.Arrow;
    //如果允许修改ComboBox中得内容的话,就改为ComboBoxStyle.DropDown
    cmbFunctionArea.DropDownStyle= ComboBoxStyle.DropDownList;
    cmbFunctionArea.Dock = DockStyle.Fill;cmbFunctionArea.SelectionChangeCommitted += new EventHandler(cmbFunctionArea_SelectionChangeCommitted1); dgtb.TextBox.Controls.Add(cmbFunctionArea); 以上代码写在formload里就可以
    ---------------------------------------------------------------------------------
    //把ComboBox中得数据写到DG里
    private void cmbFunctionArea_SelectionChangeCommitted1(object sender, EventArgs e)
    {
    this.dataGrid1[this.dataGrid1.CurrentCell] = ((ComboBox)sender).SelectedItem.ToString();
    }
      

  4.   

    combox已经绑定了datagrid
    现在要实现的是
    要展开ComboBox和在ComboBox中输入新的数据
      

  5.   

    楼主给我发MSG收到了,编程就是一种思想,示例代码可以参考楼上的,
    核心的就是
    dataGrid.GetCellBounds()
    用它来定位下拉框的位置
      

  6.   

    Rectangle rc = this.dataGrid1.GetCellBounds(this.dataGrid1.CurrentRowIndex,this.dataGrid1 .CurrentCell.ColumnNumber);
    this.comboBox1 .Bounds= this.RectangleToClient(this.dataGrid1.RectangleToScreen(rc));
    this.comboBox1.Focus();
    this.comboBox1.Visible = true;
    thank you
    搞懂后确实很简单
      

  7.   

    好贴,不过有点错误,应该是这样吧:Rectangle rc = this.dataGrid1.GetCellBounds(this.dataGrid1.CurrentCell.RowNumber,this.dataGrid1 .CurrentCell.ColumnNumber);
    this.comboBox1 .Bounds= this.RectangleToClient(this.dataGrid1.RectangleToScreen(rc));
    this.comboBox1.Focus();
    this.comboBox1.Visible = true;
    thank you
    搞懂后确实很简单