【问题标题】:What must I do to make edits on a DataGridView immediately available?我必须做什么才能使 DataGridView 上的编辑立即可用?
【发布时间】:2012-10-05 07:17:07
【问题描述】:

我有一个DataGridView 绑定到FileItem 对象列表,通过FileItemBindingSource。我想简单地将网格绑定到我的列表,并让用户选中或取消选中每个项目的复选框列,然后单击按钮,从网格中获取所有选中的项目。现在,如果我使用以下代码,即使在 UI 中选中了一些框,返回的对象都已将 Checked 设置为 false。

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    FileItemBindingSource.EndEdit()
    Dim allFiles = DirectCast(FileItemBindingSource.DataSource, IEnumerable(Of FileItem))

    Dim checkedFiles = allFiles.Where(Function(f) f.Checked).Select(Function(f) f.FilePath)

End Sub

我将数据绑定如下:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    FileItemBindingSource.DataSource = GetFiles()

End Sub

我必须怎么做才能在我的 Checked 列上进行编辑?

【问题讨论】:

    标签: winforms data-binding datagridview


    【解决方案1】:

    我认为你应该把 Datagridview.beginInvoke();在您拉出选中的对象之前。

    我也有这个问题。从未包含最后选中的行或始终包含最后未选中的行。但是,我无权访问该代码,并且我不能 100% 确定这是要使用的命令。

    【讨论】:

    • 值得注意的是,我通过取消 BindingSource 并将我的对象直接绑定到网格实现了我想要的。不过,这不是一个真正的答案。
    猜你喜欢
    • 1970-01-01
    • 2011-04-21
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多