【问题标题】:ComboBox in DataGridView how to populate another combobox in the second columnDataGridView中的组合框如何在第二列中填充另一个组合框
【发布时间】:2019-11-26 11:30:22
【问题描述】:

晚上好,我在使用 DataGridComboBox 在 DataGridView 中填充记录时遇到问题。

这是我想要的,但我无法得到。

我在DataGridView1 中创建了DataGridComboBoxColumn,在ComboBox DropDown -"Machine","Materials" 中有2 个项目。如果我在ComboBox 列中选择"Machine"。它将在下一个单元格中添加另一个 ComboBoxColumn,其中包含 2 个项目 - "Machine 1", "Machine 2"。此外,如果我选择"Materials",它将更改"Material 1""2" 中的项目。

任何人都可以帮助我,非常感谢。谢谢。

【问题讨论】:

  • 请检查thisthis
  • 我会检查一下这位先生。感谢分享。
  • 您好,DBGetData("Select....) 出现错误
  • 好吧,没有代码可以理解你的逻辑,我能提供的最好的帮助是提供一些有用的链接来指导你。
  • 您提供的第二个链接中的代码是我需要的逻辑,但我无法弄清楚 DBGetdata 的来源。

标签: vb.net winforms datagridview


【解决方案1】:

试试这个代码。

Dim sourceGrid As DataGridView = Me.DataGridView1
Dim targetGrid As DataGridView = Me.DataGridView2

Dim targetRows = New List(Of DataGridViewRow)
For Each sourceRow As DataGridViewRow In sourceGrid.Rows
    If (Not sourceRow.IsNewRow) Then
        Dim targetRow = CType(sourceRow.Clone(), DataGridViewRow)
       For Each cell As DataGridViewCell In sourceRow.Cells
            targetRow.Cells(cell.ColumnIndex).Value = cell.Value
        Next
        targetRows.Add(targetRow)
    End If
Next
targetGrid.Columns.Clear()
For Each column As DataGridViewColumn In sourceGrid.Columns
    targetGrid.Columns.Add(CType(column.Clone(), DataGridViewColumn))

下一个

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多