Add Items to a ComboBoxCellType

Posted by: thomas.bittel on 18 August 2020, 7:50 pm EST

    • Post Options:
    • Link

    Posted 18 August 2020, 7:50 pm EST

    This code works fine:

    Dim comboType = New ComboBoxCellType()

    FpSpread1.ActiveSheet.ActiveCell.CellType = comboType

    comboType.Items = New String() {“Alpha”, “Bravo”, “Charley”}

    but when I try to add a value to the ComboBox-Items the items will not be appended:

    comboType.Items.Append(“new value”)

    How can I append items to a ComboBoxCellType?

  • Posted 19 August 2020, 8:20 am EST

    Hi

    To meet your requirement, please try to use ListControl property of the ComboBoxCellType and then use ListControl.Items.Add method to add items, as follows:```

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

    comboType = New ComboBoxCellType()

    FpSpread1.ActiveSheet.ActiveCell.CellType = comboType

    list = New ListBox()
    list.Items.AddRange(New String() {"Alpha", "Bravo", "Charley"})
    comboType.ListControl = list
    

    End Sub

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

    comboType.ListControl.Items.Add(“New Value”)

    End Sub

  • Posted 19 August 2020, 7:49 pm EST

    It works, thank you.

    But I don’t understand why this must be so complicated.

    The more intuitive approach is “Items.Append”.

    Greetings,

    Thomas

  • Posted 20 August 2020, 6:24 pm EST

    Hi Thomas,

    I agree but items cannot be added to ComboBoxCellType 's Items property as it is of type String(). If you want to use the Items property you should convert it to a list and invoke the Add method, as follows:

    Dim newItems = comboType.Items.ToList()
    newItems.Add("New Value")
    comboType.Items = newItems.ToArray()
    ```Alternatively, you can use the ListControl and invoke its Items.Add method like mentioned earlier.
    
    With regards,
    
    Thanks,
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels