Combobox ItemData

Posted by: michaelpaschalmp-fp on 8 September 2017, 2:33 pm EST

  • Posted 8 September 2017, 2:33 pm EST

    I need to associate a list of unique names with a non-unique list (duplicates allowed) of types.  Can this be done using the combobox items for the names and the combobox itemdata for the types?
  • Replied 8 September 2017, 2:33 pm EST

    Hello,

    You can use the code given below in order to set the unique ItemData and duplicated Items in ComboBoxCellType.

    FarPoint.Win.Spread.CellType.ComboBoxCellType combo = new FarPoint.Win.Spread.CellType.ComboBoxCellType();

            void btnSetCellType_Click(object sender, EventArgs e)

            {

                string[] cbstr;

                cbstr = new String[] { "One", "Two", "Three", "Two", "Three" };

                string[] strval;

                strval = new String[] { "1", "2", "3", "4", "5" };

                combo.Items = cbstr;

                combo.ItemData = strval;

                combo.EditorValue = FarPoint.Win.Spread.CellType.EditorValue.Index;

                fpSpread1.Sheets[0].Columns[0].CellType = combo;

            }

           void btnGetValue_Click(object sender, EventArgs e) // to open Excel file and saving it again using Excel only

            {

                listBox1.Items.Add(fpSpread1.ActiveSheet.ActiveCell.Value.ToString());

                listBox1.Items.Add(combo.GetEditorValue().ToString());

            }

    Hope this will help you. Thanks.

  • Replied 8 September 2017, 2:33 pm EST

    In my application. it's the ITEMDATA that are NOT unique (e.g., DIM PolicyCode As String() = {"2", "2", "2", "2", "3"} ), while the ITEMS  are unique (e.g., DIM PolicyName As String() = {"Bob", "Mary", "John", "Jane", "Joe"}.  The problem is that no matter what the user does, selecting "Mary", "John" or "Jane" results in "Bob", because "Bob" is first ITEM associated with the ITEMDATA value of "2" (EditorValue = FarPoint.Win.Spread.CellType.EditorValue.ItemData).

    In other words, it looks like the ITEMDATA must contain unique values. 

  • Replied 8 September 2017, 2:33 pm EST

    Hello,

    Items property is an array of strings that are displayed in the
    drop-down portion of the combo box which is the list that user sees, wherein the ItemData property is an array of strings that we
    use as the real values that are kept in the data model and are separate
    from what is displayed. Hence it has to be unique when the EditorValue is being set to ItemData else with duplicated ItemData array of strings you need to set the EditorValue to String.

    Thanks.

  • Replied 8 September 2017, 2:33 pm EST

    OK, got it.  If I change EditorValue to EditorValue.Index, how do I retrieve the ItemData value associated with the index value, using cell referencing.
  • Replied 8 September 2017, 2:33 pm EST

    Hello,

    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. Here is the code to retrieve the ItemData value associated with the index value retrieved from the active cell.

            string[] cbstr;
            string[] strval;

            void btnSetCellType_Click(object sender, EventArgs e)
            {
                cbstr = new String[] { "One", "Two", "Three", "Four", "Five" };
                strval = new String[] { "2", "2", "2", "2", "3" };
                combo.Items = cbstr;
                combo.ItemData = strval;
                combo.EditorValue = FarPoint.Win.Spread.CellType.EditorValue.Index;
                fpSpread1.Sheets[0].Columns[0].CellType = combo;
            }
            void btnGetValue_Click(object sender, EventArgs e) // to open Excel file and saving it again using Excel only
            {
                listBox1.Items.Add("Items :" + fpSpread1.ActiveSheet.ActiveCell.Value.ToString());      
                listBox1.Items.Add("ItemData :" + strval[(int)fpSpread1.ActiveSheet.ActiveCell.Value].ToString());
            }

    Hope this will help you. Thanks.

Need extra support?

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

Learn More

Forum Channels