vb.net 将项目添加到 datagridview 组合框列中现有的组合框单元格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18978648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:12:48  来源:igfitidea点击:

add items to an already existing combobox cell in a datagridview comboBox column

vb.netdatagridviewvb.net-2010

提问by user2194838

How can I add items to an already existing combobox cell in a datagridview combobox column. ProductGrid is dataGridView.

如何将项目添加到 datagridview 组合框列中已经存在的组合框单元格。ProductGrid 是 dataGridView。

       With ProductGrid
         Dim objSerialNumber As New DataGridViewTextBoxColumn
        With objSerialNumber
            .Name = "SerialNumber"
            .HeaderText = "SerialNumber"
            .Visible = False
            .Width = lGridWidth * 1.2
        End With
        .Columns.Add(objSerialNumber)
       End With

There is another function where i have to add items in SerialNumber comboBox. And item that i have to add is in array. And which line of code will be used to remove items from comboBox if already added in ComboBox column.

还有另一个功能,我必须在 SerialNumber 组合框中添加项目。我必须添加的项目在数组中。如果已经添加到 ComboBox 列中,哪一行代码将用于从组合框中删除项目。

采纳答案by user2194838

I solved the problem stated above in this manner. gSerialNumberArray contains items that i have to add.

我以这种方式解决了上述问题。gSerialNumberArray 包含我必须添加的项目。

 Dim cbCell As New DataGridViewComboBoxCell

    For k = 0 To ProductGrid.Rows.Count - 1
        cbCell = ProductGrid.Rows(k).Cells("SerialNumber")
        For iIndex = 0 To UBound(gSerialNumberArray)
            cbCell.Items.Add(gSerialNumberArray(iIndex))  
        Next
    Next

回答by sk2185

Normally combobox add item Command is applicable instead of using your DatagridviewCombobox Cell Name

通常组合框添加项目命令是适用的,而不是使用您的 DatagridviewCombobox 单元格名称

dgvcomb.Items.Add("30")

回答by Sabir Khalil

Column4.Items.Add(tds1.Tables(0).Rows(ij).Item(0))

Column4.Items.Add(tds1.Tables(0).Rows(ij).Item(0))

回答by Trebuchet

You can also use:

您还可以使用:

cbCell.Items.AddRange(strArray)

cbCell.Items.AddRange(strArray)

If you already loaded the items into an array, this loads them all in the pulldown. If you are collecting them from say a database table, use the arraylist function to load the database items into the list, then convert the array list to an array.

如果您已经将项目加载到数组中,这会将它们全部加载到下拉列表中。如果您从数据库表中收集它们,请使用 arraylist 函数将数据库项加载到列表中,然后将数组列表转换为数组。