如何使用数据绑定在datagridview上对组合框进行数据绑定

时间:2017-05-03 23:22:39

标签: vb.net data-binding datagridview datagridcomboboxcolumn

所以我的项目有一个datagridview,这是我的datagridview的代码

  With DataGridView1
             .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
             .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
             .CellBorderStyle = DataGridViewCellBorderStyle.Single
             .GridColor = Color.Black

             .SelectionMode = DataGridViewSelectionMode.FullRowSelect
             .MultiSelect = False
             .AllowUserToResizeColumns = False
             .AllowUserToAddRows = False
             .ReadOnly = True

             .AutoGenerateColumns = False
              Me.DataGridView1.Columns("cod_produto").Visible = True
              Me.DataGridView1.Columns("nome_produto").Visible = True
              Me.DataGridView1.Columns("descricao").Visible = True
              Me.DataGridView1.Columns("qtd_existente").Visible = True
              Me.DataGridView1.Columns("qtd_minima").Visible = True
              Me.DataGridView1.Columns("precounitario_venda").Visible = True
              Me.DataGridView1.Columns("nome_fornecedor").Visible = True
              Me.DataGridView1.Columns("categoria_produto").Visible = True
          end with
          Dim listaproduto As List(Of Produto) = CAD.CAD_Listar.ObterProduto()

          Me.BindingSource1.DataSource = listaproduto
         DataGridView1.DataSource = BindingSource1

现在我想创建另一个包含我在这里做的组合框的列

    Dim lstcategoria As List(Of CategoriaProduto) = CAD.CAD_Listar.ObterCategoria()

        Dim comboboxColumn As New DataGridViewComboBoxColumn
        With comboboxColumn
            .DataSource = lstcategoria
            .DisplayMember = "categoriaproduto"
            .ValueMember = "cod_categoriaproduto"
        End With
        DataGridView1.Columns.Add(comboboxColumn)

但这不起作用,它没有任何提示,但组合框只保留没有items.i知道列表工作,因为如果我创建一个正常的组合框(不在组合框中)组合框填充的值列表。但由于某些原因,当我尝试做同样的事情,但在comboboxcolumn它只是没有填补。有人可以帮我吗?感谢

0 个答案:

没有答案