How to set either 'Index' or 'Text' for a ComboBox

Posted by: ulrika on 8 September 2017, 12:30 pm EST

  • Posted 8 September 2017, 12:30 pm EST

    I have created a spread where some columns use a ComboBox celltype according to:

    <FONT size=2>

    <FONT color=#008080>ComboBoxCellType</FONT><FONT size=2> </FONT>comboBoxCellType1 = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>ComboBoxCellType</FONT><FONT size=2>();

    </FONT><FONT size=2>

    comboBoxCellType1.ButtonAlign = </FONT><FONT color=#008080 size=2>ButtonAlign</FONT><FONT size=2>.Right;

    comboBoxCellType1.EditorValue = </FONT><FONT color=#008080 size=2>EditorValue</FONT><FONT size=2>.ItemData;

    comboBoxCellType1.ListControl = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>ListBox</FONT><FONT size=2>();

    </FONT><FONT color=#008080 size=2>StringCollection</FONT><FONT size=2> myList = getList();

    </FONT><FONT color=#0000ff size=2>foreach</FONT><FONT size=2> (</FONT><FONT color=#0000ff size=2>string</FONT><FONT size=2> strItem </FONT><FONT color=#0000ff size=2>in</FONT><FONT size=2> myList)




    </FONT><FONT color=#0000ff size=2>this</FONT><FONT size=2>.fpSpread1_Sheet1.Columns.Get(1).CellType = comboBoxCellType1;</FONT>

    <FONT size=2><FONT size=3>Then, later in my code, I would like to initialize the ComboBox with an input string. If the input string is null or empty the combobox should instead display the first value in the list</FONT></FONT>

    <FONT size=2>

    <FONT color=#0000ff>if</FONT> (<FONT color=#0000ff>string</FONT>.IsNullOrEmpty(myInputString))


    fpSpread1_Sheet1.Cells[i, 1].Value = 0;


    <FONT color=#0000ff>else

    </FONT><FONT size=2>


    fpSpread1_Sheet1.Cells[i, 1].Text = myInputString;


    <FONT size=3>This works fine when the string is empty. However, I cannot set the text to the selected input string (in my test case I check earlier to make sure that the input string is already one of the Items for this comboBox). I suspect that this is because I have set the EditorValue to Index. But I have to do this to be able to select the first item in the case where the input string is empty. How do I solve this?</FONT>

  • Replied 8 September 2017, 12:30 pm EST


    You are correct at what the issue is. You need to convert the string to its item number equivalent. You can search the Items array in the combobox values to find the index of the string and then find the ItemData at that location to set for the Value of the cell.

Need extra support?

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

Learn More

Forum Channels