none
combobox RRS feed

  • Question

  • hi all,

    am using combobox in my application, am adding values to combobox dynamically.but at 0th place no item is showing.

    hera is the code.

     ComboBox_EPC2.Items.Add(sEPC);

    sEPC is the array. having some values.

    suppose sEPC is having 

    aaa

    bbb

    ccc

    when am adding to combobox it's showing as

    blank space

    aaa

    bbb

    ccc

    i want it without blank in combobox.

    • Moved by CoolDadTx Monday, October 28, 2013 1:59 PM Winforms related
    Monday, October 28, 2013 12:53 PM

Answers

  • So you want to bind a combo to an array?  If so then Add isn't the correct approach.  A combo works with anything and it'll ToString on that object.  If you pass it an array you are not going to be populating it with the array elements.

    To bind an array to a combo you can either manually bind by using Items.AddRange or automatically by assigning the array directly to DataSource.  In both cases the array elements will be added to the combo.  If you need to add items in addition to the array then Items is probably the easier route.

    Refer to MSDN for an example.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Monday, October 28, 2013 1:59 PM