【问题标题】:Dropdown comboboxcell on button click单击按钮时的下拉组合框单元格
【发布时间】:2014-04-24 06:13:08
【问题描述】:

IDE:Visual Studio C# .net 4.0

在我的项目中,我有一个 datagridview,其中有一个组合框单元格,它在下拉列表中有 4 个项目 a、b、c、d,我想在用户单击 button1 时显示该下拉列表

datagridviewComboboxcell on button_click 事件。

button_Onclick(sender s, eventargs e)
{
  DataGridViewComboBoxCell dgv = (DataGridViewComboBoxCell)gvTeam2.Rows[0].Cells[4]; 

  dgv.dropdown = true // available in normal combobox
  // not available in datagridview combobox cell.
}

【问题讨论】:

  • 你的问题很不清楚,你的问题到底是什么?如果您是我们社区的新手,请阅读How to ask
  • 你没有得到什么,我已经说得更清楚了,看看并删除 -ve 评级。
  • 因此,如果我理解正确,您是在询问如何使自定义按钮显示下拉菜单?您编写的代码应该可以做到这一点,您也可以发布您的标记代码吗?
  • 不,它不会这样做。他说DataGridViewComboBoxCell没有下拉选项
  • 是的,你明白我的意思,但此代码不适用于 datagridviewComboBoxcell,仅适用于普通组合框。

标签: c# .net winforms combobox


【解决方案1】:

试试这个:

gvTeam2.CurrentCell = gvTeam2[4, 0];
gvTeam2.BeginEdit(false);
gvTeam2.EditingControl as DataGridViewComboBoxEditingControl).DroppedDown = true;

【讨论】:

  • 不工作,错误-> 无法解析符号 .DroppedDown
  • 我看到我错过了第三行的左括号,您是否在代码中完成了它?我已经在演示应用程序上对其进行了测试,它似乎对我来说工作正常......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-28
  • 1970-01-01
  • 2018-09-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多