ComboBox加到datagrid的问题 在ComboBox已经绑定数据的情况下1.怎么样才能在ComboBox加到datagrid后使用 Alt + 方向键 展开ComboBox 2.怎么样才能在ComboBox中输入新的数据 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DataTable默认情况下ColumnStyle有文本列和是否列,可以自定义一个ComboBoxColumn我一般不用这种方式 ,这种方式虽然自定义非常灵活但是要把人搞死所以我一般就是在DataGrid控件的容器中加一拖一个ComboBox,单击DataGrid时我判断是否单击了要显示下拉列表的列,如果是就把数据加载到ComboBox并移到当前单元格所在位置并显示,可以设置ComboBox相应类型就可以输入数据,当它失去焦点时把数据写到单元格 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是一样的思路 DataGridTextBoxColumn dgtb = (DataGridTextBoxColumn)this.dataGrid1.TableStyles[0].GridColumnStyles[2]; //这里决定哪一列是ComboBoxComboBox cmbFunctionArea = new ComboBox();//这里如果你是绑定数据到ComboBox就写数据绑定得代码cmbFunctionArea.Items.AddRange(new object[]{"选项一","选项二","选项三"});cmbFunctionArea.Cursor = Cursors.Arrow;//如果允许修改ComboBox中得内容的话,就改为ComboBoxStyle.DropDowncmbFunctionArea.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();} combox已经绑定了datagrid现在要实现的是要展开ComboBox和在ComboBox中输入新的数据 楼主给我发MSG收到了,编程就是一种思想,示例代码可以参考楼上的,核心的就是dataGrid.GetCellBounds()用它来定位下拉框的位置 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搞懂后确实很简单 好贴,不过有点错误,应该是这样吧: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搞懂后确实很简单 全局钩子! 请问如何在自定义函数中返回两个值? 缓存的问题 想做这样一个简单的功能 [请教]知道的朋友请进:如何实现窗体/web软件注册功能? xml 添加节点怎么老多个连接 推荐两本asp.net安全的电子书 窗体回调 如何获取到另一个窗体中的值 怎样用adapter填充/更新DataSet里面有关联的表? System.IO.InvalidDataException压缩文件错误!? 请问如何在datagird中加入combobox? 如何将Richtextbox中的图片提取出来存为另外一张图片
所以我一般就是在DataGrid控件的容器中加一拖一个ComboBox,单击DataGrid时我判断是否单击了要显示下拉列表的列,如果是就把数据加载到ComboBox并移到当前单元格所在位置并显示,可以设置ComboBox相应类型就可以输入数据,当它失去焦点时把数据写到单元格
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是一样的思路
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();
}
现在要实现的是
要展开ComboBox和在ComboBox中输入新的数据
核心的就是
dataGrid.GetCellBounds()
用它来定位下拉框的位置
this.comboBox1 .Bounds= this.RectangleToClient(this.dataGrid1.RectangleToScreen(rc));
this.comboBox1.Focus();
this.comboBox1.Visible = true;
thank you
搞懂后确实很简单
this.comboBox1 .Bounds= this.RectangleToClient(this.dataGrid1.RectangleToScreen(rc));
this.comboBox1.Focus();
this.comboBox1.Visible = true;
thank you
搞懂后确实很简单