【问题标题】:How to add a new row to Winforms DataGridView in my custom column如何在我的自定义列中向 Winforms DataGridView 添加新行
【发布时间】:2015-08-13 08:59:03
【问题描述】:

我为我的 DataGridView 创建了一个自定义列,该列在可编辑模式下使用。当我在每一列中输入数据时,dataGrid 会自动添加一个新行,如下所示:

但在我的自定义列中它不会发生。

自定义列的哪一部分负责添加新行,我应该怎么做。

编辑: 我为我的自定义列实现了三个类:

public class DataGridViewLookupColumn : DataGridViewColumn {...}
public class DataGridViewLookupCell : DataGridViewTextBoxCell{...}
public class DataGridLookupControl : LookupControl, IDataGridViewEditingControl{...}

编辑: 我正在使用绑定源填充我的 DatagridView。

this.dataGrid.DataSource = BindingSource;
BindingSource.DataSource = model;
model=await this.EntityService.AdvancedSearchAsync(...);

以上代码是从应用程序中的三个不同点收集的,以显示我的数据和应用程序的结构。

在此先感谢您的宝贵时间和您的考虑。

【问题讨论】:

  • 你正在使用什么DataSource。显示代码如何DataGridView 填充数据以及如何将新行添加到DataSource
  • 您能否至少向我们展示一下您的自定义列实现了哪些事件?
  • @TaW 我在朋友的回复中编辑了问题。
  • @Fabio 我的问题的第二个编辑是给你的先生。
  • 不要发布实现,只发布事件和函数 names,以便我们可以看到 which 已编码。许多是可选的,其他推荐(如克隆)。我用一个只显示的自定义列做了一个测试,它有同样的问题,但它只用于显示..

标签: c# winforms datagridview designer datagridviewcolumn


【解决方案1】:

我终于想出了如何解决它。 这只是

DataGridView.NotifyCurrentCellDirty(true);

我将此代码添加到我的更改事件中,我的问题解决了。

【讨论】:

    猜你喜欢
    • 2010-11-29
    • 1970-01-01
    • 2021-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    相关资源
    最近更新 更多