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?
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.
"…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.
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.
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.
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?
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");
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.