问题标签 [datagridviewcomboboxcell]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
4732 浏览

c# - 一旦显示表单,DataGridViewComboBoxCell.DataSource 被设置为 null

我在表单的事件处理程序期间添加DataGridViewComboBoxColumna并设置列中每个的 DataSource 。但是,一旦显示表单,每个表单的 DataSource都已设置为. 这是我用来填充列及其单元格的代码:DataGridViewLoadDataGridViewComboBoxCellDataGridViewComboBoxCellnull

如果我将它放在表单加载后单击的按钮中,则此代码完全符合预期,但是在表单加载期间执行时,数据源被清除。有什么建议么?

0 投票
1 回答
9049 浏览

data-binding - 将组合框列数据绑定到每行的数据网格视图(不是整个列)

有一些关于这个的帖子,但经过几个小时的搜索,我仍然找不到我需要的东西。

以下帖子中的答案几乎让我得到了我想要的: Combobox for Foreign Key in DataGridView

问题一:

从产品具有许多许可证的示例开始,我的数据库映射都是多对一的关系,这意味着我的许可证类包含对产品类的引用。License 类没有 ProductId 的属性,因为可以通过 Product 引用检索该属性。我不想用对 Product 和 ProductId 属性的引用来混淆 License 类,只是为了使 UI 中的绑定更容易。

因此,我无法将其设置DataPropertyName为 Id 字段。它必须是类引用名称,如下所示:

****更新**** 我能够通过将 Product.Id 指定为 DataPropertyName 来使其部分工作而无需创建 ProductId 属性,如下所示:

但是,这样做时,它破坏了数据绑定,导致我手动获取和设置单元格值。

我还看到了有关绑定到 DataGridView 单元格的帖子,但是当我这样做时数据绑定会中断,并且数据源本身永远不会更新:

也许我做错了什么,或者也许有不同的方式。有人可以在这里帮忙吗?

问题2:

如何为每个产品显示不同的许可证列表?换句话说,许可证的组合框列表对于网格中的每个产品都是不同的。我想使用数据绑定来做到这一点,所以我不必自己获取和设置值。

0 投票
3 回答
22252 浏览

c# - 单击即可打开下拉列表(在数据网格视图中)项目

DropDownButton如何避免在 a中使用的双击DataGridView?现在,我可以DataGridView通过单击两次或多次来查看其中的下拉项目。第一次选择单元格,第二次单击DropDownButton箭头时,它显示列表。如何通过单击实现相同的目标?

0 投票
2 回答
8219 浏览

datagridview - DataGridviewComboBox 需要单击 2 次才能显示项目列表

可能重复:
单击即可打开下拉列表(在数据网格视图中)项目

我们有一个 DataGridView,其中一列是具有 DropDownButton 样式的 ComboBox。DataGridView 处于 FullRowSelect 模式。假设我有 5 行,并且在 DataGridView 中选择了第 0 行。

我想从 -say-row 2 的 ComboBox 中选择一个项目,因此我单击 ComboBox 的小箭头。当我这样做时,首先选择 DataGridView 的第 2 行。组合框尚未打开。只有第二次单击才能打开 ComboBox。

事实上,它曾经需要 3 次点击,但后来我们重载了 CellMouseDown 来执行以下操作:

有了这个,我们只需要点击 2 次。有没有办法一键显示 ComboBox 项目?

编辑:我还应该提到的是,如果我单击 ComboBox 本身,而不是单击 ComboBox 的小箭头,则需要单击 3 次才能显示 ComboBox 项!

0 投票
4 回答
4008 浏览

c# - DataGridViewComboboxCell.Value 上的 FormatException

我有一个我无法弄清楚的问题。

我有一个 DataGridViewComboboxCell,

When the option "Klant aanvraag" is selected the user gets a window where the user can choose another customer. 这是因为没有为该客户分配特定项目的用户。当用户选择一个时,它将在 Combobox 中使用以下代码进行更改。

klantindex是需要选择的客户,因为它是从组合框中检索的。在我看来,这是正确的对象。

在此之后,datagridview_dataerror在我得到带有以下异常文本的 Format 异常的地方引发了事件。

DataGridViewComboBoxCell 值无效。

问题是什么?

0 投票
2 回答
2803 浏览

c# - 如何在 DatagridView 组合框 SelectedIndexChanged 更改事件上重置 DatagridView 组合框单元格

“这都是关于当我更改另一个数据网格组合框单元格时重置数据网格视图组合框单元格”

示例 :: 如果我在 DataGridView 中有四行,它们都包括组合框

可能吗!或任何建议

0 投票
0 回答
583 浏览

c# - Datagridview 中的 C# 组合框行为

我有一个 Datagridview,其中有一列有一个组合框作为编辑控件。假设我在第一行的组合框中选择值 X。当我在第 2 行打开组合框时,它将选择值 X 作为默认值(当组合框在编辑之前为空时),即使值 X 不是组合框列表中的第一项。为什么它不选择第一个项目(如果它仍然想选择一个项目)?

我不知道它是否相关,但网格和组合绑定到 Linq2sql 对象。

0 投票
1 回答
3615 浏览

c# - DatagridViewComboBoxColumn 的自定义绘制

我正在使用 a DataGridViewDataGridViewComboBoxColumn我需要在组合框项目的左侧添加图标。我目前正在使用EditingControlShowing事件和ComboBox.DrawItem事件,如下所示:

问题是只有在单元格处于编辑模式时才会绘制图标。只要我单击单元格外部的某个位置,CellEndEdit就会触发事件并且重新绘制单元格(没有图标)。

我尝试使用该DataGridView.CellPainting事件来解决此问题,但它会导致下拉按钮DataGridViewComboBoxColumn消失。

在用户完成编辑单元格后如何绘制图标的任何想法?

0 投票
3 回答
27008 浏览

c# - c# add a dgv row with a dataGridViewComboBoxCell

I'm currently trying to add a ComboBox to a dataGridView.

In the DGV, there are 5 columns: checkbox, string, string, combobox, combobox.

both combobox-columns are configured as datagridviewcomboboxcolumns (via VisualStudio designer). My problem is to add rows.

My current try is: the columns are already defined and I add rows via dataGridView.Rows.Add. For that, I'm using an array of objects. Example:

This passes without any errors. But logically, the comboBoxes aren't filled with anything.

I tried setting a datasource to the 4th and 5th cell of a row:

Error...Using ROW.dataGridViewComboBoxCell.Items.Add: Items are not displayed...

filling obj[3] and 4 with a new DGVcomboBoxCell or -Column:

Further information: Each column should have the same Items in the comboBoxes. (These are previously loaded via internet, as xml). Setting a dataSource to the two columns destroys the whole DGV (I think because the other colmns don't have a Datasource). In a nutshell: How to add Rows to a DGV which contain comboboxes filled with items?

Sincerely, NoMad

edit: here's some code to solve my problem:

First add a row, cast columns, configure them and add them to the row. No Columns need to be previously specified in the designer.

0 投票
1 回答
1447 浏览

c# - 如何从填充 DataGridViewComboBox 中选择一个项目

项目:Winforms,.NET 框架:3.5 (Visual Studio 2008)

我的问题是:

我有DataGridView几列,一些类型和另一种类型DataGridViewTextBoxColumnDataGridViewComboBoxColumnDataGridViewComboBoxColumn由实体框架提供的实体填充。

当您运行并加载表单时,很好

但是当在运行时我想从集合中选择一个项目时,问题就来了DataGridViewComboBoxColumn

在事件中CellEndEdit

  • 尝试从组合框中选择一项
  • 尝试选择实体的对象
  • 尝试通过链或显示成员值进行选择

我无法选择所需的项目,我得到了例外:

DataGridViewComboBoxCell 值无效