Combobox - Selecting item shows value instead of item text

Using the following code, I'm wanting to be able to select the 1st item in the list "Aspose" and have it displayed. Instead, it display "1".

//Accessing the worksheet of the Grid that is currently active

Worksheet sheet = gridDesktop1.GetActiveWorksheet();

//Accessing the location of the cell that is currently in focus

CellLocation cl = sheet.GetFocusedCellLocation();

//Creating an array of items or values that will be added to combobox

string[] items = new string[3];

items[0] = "Aspose";

items[1] = "Aspose.Grid";

items[2] = "Aspose.Grid.Desktop";

string[] values = new string[3];

values[0] = "1";

values[1] = "2";

values[2] = "3";

//Adding combobox to the Controls collection of the Worksheet

sheet.Controls.AddComboBox(cl.Row, cl.Column, items, values);

Hi,

Please change your code to the following for your need:
/Accessing
the worksheet of the Grid that is currently active

Worksheet sheet = gridDesktop1.GetActiveWorksheet();

//Accessing the location of the cell that is currently in focus

CellLocation cl = sheet.GetFocusedCellLocation();

//Creating an array of items or values that will be added to combobox

string[] items = new string[3];

items[0] = "Aspose";

items[1] = "Aspose.Grid";

items[2] = "Aspose.Grid.Desktop";

string[] values = new string[3];

values[0] = "1";

values[1] = "2";

values[2] = "3";

//Adding combobox to the Controls collection of the Worksheet

sheet.Controls.AddComboBox(cl.Row, cl.Column, items);


Thanks you.

That might have been a bad example. I want to be able to access the value of the selected item and the values aren't going to start with 1. They might be 5, 10, 15, etc.

If I selected Aspose and wanted to get it's value of 5, how would I do that?

Can someone please answer my last question?

Hi,

We will get back to you soon.

Thanks for being patient!

Hi,

"I want to be able to
access the value of the selected item and the values aren’t going to
start with 1. They might be 5, 10, 15, etc.

If I selected Aspose and wanted to get it's value of 5, how would I do that?"


I think you may try the following sample code for your requirement.

string[] items = new string[3];
items[0] = "Aspose";
items[1] = "Aspose.Grid";
items[2] = "Aspose.Grid.Desktop";
string[] values = new string[3];
values[0] = "5";
values[1] = "15";
values[2] = "20";
gridDesktop1.Worksheets[0].Controls.AddComboBox(2, 2, items, values);


Thank you.

I'm using 2.0.3.2006

I ran your test and when I selected Aspose, "5" was displayed which is getting back to my original problem.

I realize if I DO NOT specify the values, the text will be displayed but if you have both items and values, when selecting an item, the value ends up getting displayed which is what I do not want.

Hi,

"…but if you have both items and values, when selecting an item, the value ends up getting displayed which is what I do not want."
We are not sure about your requirement, it looks you want to select an item from the drop down, the corresponding value should not be displayed in the cell. But, again I already suggested you not to use values when adding combobox, i.e.
sheet.Controls.AddComboBox(cl.Row, cl.Column, items);

We appreciate if you could you elaborate and give details how should we cope with the combo box, we will check it soon.

Thank you.

Okay, let's give this one more shot. If we're still unclear after this, please give me a phone number so I can talk to someone to explain.

I've attached a sample application. Please run it and let me know how it goes. There will be a combobox in the 1st row, 1st column.

After selecting one of the items, you should see a messagebox that will walk you through the problem I'm having.

Thanks.

Hi,

Now we understand your requirement. But we got to check the feasibility of the feature/enhancement and let you know about it soon.

We have logged it into our issue tracking system with an issue id: CELLSNET-15984 in any case.

Thank you.

Hi,

Please try Aspose.Cells.GridDesktop v<st1:chsdate isrocdate=“False” islunardate=“False” day=“30” month=“12” year=“1899” w:st=“on”>2.1.0</st1:chsdate>.2004(attached).
The selected item text of ComboBox will be shown in the cell now. Hopefully it will suit your requirement.

Thank you.

Thanks, this is working as I would expect.

I have noticed that my Autofit is not working as normal. Could this change affected how the autofit works? It's not sizing the columns based on the size of the text displayed in my combobox.

Hi,

Please try the attached version Aspose.Cells.GridDesktop v2.1.0.2005 if it fixes the issue.

Thank you.

The issues you have found earlier (filed as 15984) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

I am attempting do something very similar to what is being discussed here. I want a combo control with display text(items) and underlying values. I want the cell to display the text even thou the underlying value is a number.
Is this possible and do I need to do anything other than call addcombobox and pass in the item and value lists?

@SEMSDev,

  1. If you use Aspose.Cells library, you cannot do this in Forms controls as this is the limitation of MS Excel for linked cells. You may confirm this in MS Excel after adding form combo box control. You will find that it will display index in the linked cell for the selected item.

I think ActiveXControls can suite your needs as the linked cell shows selected item instead of index. See the following sample code on how to add ComboBox ActiveX control (you may easily add other controls like ListBox ActiveX Control by changing its control type):
e.g
Sample code:

    //Create a new Workbook.
    Workbook workbook = new Workbook();

    //Get the first worksheet.
    Worksheet sheet = workbook.Worksheets[0];

    //Get the worksheet cells collection.
    Cells cells = sheet.Cells;

    //Input a value.
    cells["B3"].Value = "Choose Dept:";

    Style style = cells["B3"].GetStyle();
    style.Font.IsBold = true;
    //Set it bold.
    cells["B3"].SetStyle(style);

    //Input some values that denote the input range for the combo box.
    cells["A2"].Value = "Sales";
    cells["A3"].Value = "Finance";
    cells["A4"].Value = "MIS";
    cells["A5"].Value = "R&D";
    cells["A6"].Value = "Marketing";
    cells["A7"].Value = "HRA";

    //Add and access combo box, change its fill range and value property
    Shape shape = sheet.Shapes.AddActiveXControl(Aspose.Cells.Drawing.ActiveXControls.ControlType.ComboBox, 5, 0, 5, 0, 100, 20);
    Aspose.Cells.Drawing.ActiveXControls.ComboBoxActiveXControl combo = (Aspose.Cells.Drawing.ActiveXControls.ComboBoxActiveXControl)shape.ActiveXControl;
    combo.ListFillRange = "A3:A7";
    combo.Value= "Marketing";
    combo.LinkedCell = "A1";

    //Save the output Excel file
    workbook.Save("e:\\test2\\out1.xlsx");
  1. If you use Aspose.Cells.GridDesktop control, you may try using the code segment, see the document for your reference:
    Adding Cell Controls in Worksheets|Documentation

Hope, this helps a bit.

I have worked out a solution to my issue.
Thanks,

@SEMSDev

Thanks for your posting and considering Aspose APIs.

It is good to know that you have sorted out your issue. Let us know if you encounter any other issue, we will be glad to look into it and help you further.