We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Defining size on listbox


I am creating an excel file from code and for each row in a sheet I want to add a list box. It works fine using this code
Aspose.Cells.Drawing.ListBox YesNolistBox = shet.Shapes.AddListBox(y - 1, 0, 18, 0, 12, 100);
YesNolistBox.InputRange = “sheet1!A1:A2”;

however my problem is that row height varies and as a consequence of this the size on on listboxes also varies. if the row is heigh the listbox is high and if the row is smaller so is the listbox. Is there anyway I can define the size so it is same height on every row.

thanks in advance


Thanks for your query.

Well, I think you may try to specify the relevant PlacementType for your requirements, see the sample line of of code for your reference:
Sample code:

//Set the placement type.
YesNolistBox.Placement = PlacementType.FreeFloating;

Hope, this helps a bit.

Thank you.

Thanks for the reply. Unfortunatly I am not able to get it to work like i want. I am using this code for the

Aspose.Cells.Drawing.ListBox YesNolistBox = shet.Shapes.AddListBox(y - 1, 0, 18, 0, 28, 100);

YesNolistBox.InputRange = “sheet1!A1:A2”;

// YesNolistBox.DropDownLines = 2;

YesNolistBox.Shadow = true;

YesNolistBox.Placement = Aspose.Cells.Drawing.PlacementType.FreeFloating;

Aspose.Cells.Drawing.ListBox ActioncomboBox = shet.Shapes.AddListBox(y - 1, 0, 16, 0, 28, 120);

ActioncomboBox.InputRange = “sheet1!A4:A8”;

// ActioncomboBox.DropDownLines = 6;

ActioncomboBox.Shadow = true;

ActioncomboBox.Placement = Aspose.Cells.Drawing.PlacementType.FreeFloating;

But the boxes look like the attached image. I’d really appreciate to be able to control the layout of the controls in the sheet.


Hans Jørgen

Hi Hans Jørgen,

Thank you for writing back.

I believe the results are correct as per your provided code snippet. Could you please provide details about your reservations, what problems are you facing? Moreover, please share your desired results for better understanding or your requirements. You may create the desired results manually in Excel and share the spreadsheet here.

Hi Barbar

Thanks for the reply. Maybe this picture shows more clearly the problem I have. If the row is where i place the control is low the contols adjust according to this. I would like to have all controls exactly same size and then have the row height adjusted to the controls. is that possible to do in code?

Hi Hans Jørgen,

Thank you for writing back.

What I understand from your recent post is that you do not wish the shape to re-size while changing the row height or column widths. As you are already setting the Shape’s Placement type to Free Floating so the shapes should not re-size with row height. I have also tested the scenario on my side while using the following piece of code and Aspose.Cells for .NET 8.7.2. Unfortunately, I am not able to observe the said problem. In addition, I have demonstrated how you can re-size the row height according to the shape height. In case my understanding is correct and you still face the same issue, please provide us an executable sample application to demonstrate the problem.


// Create a workbook object
Workbook workbook = new Workbook();
// Get the first worksheet
Worksheet worksheet1 = workbook.Worksheets[0];
// Fill different cells with data in the range
worksheet1.Cells[0, 0].PutValue(“Blue”);
worksheet1.Cells[1, 0].PutValue(“Red”);
worksheet1.Cells[2, 0].PutValue(“Green”);
worksheet1.Cells[3, 0].PutValue(“Yellow”);
int rowNum = 10;
// Add a new combo box
Aspose.Cells.Drawing.ComboBox box = worksheet1.Shapes.AddComboBox(rowNum, 0, 18, 0, 28, 100);
box.InputRange = “sheet1!A1:A4”;
box.Shadow = true;
box.Placement = Aspose.Cells.Drawing.PlacementType.FreeFloating;

worksheet1.Cells.Rows[rowNum].Height = box.HeightPt;

rowNum = 20;

// Add a new list box.
Aspose.Cells.Drawing.ListBox listBox = worksheet1.Shapes.AddListBox(rowNum, 0, 18, 0, 128, 100);
listBox.Placement = PlacementType.FreeFloating;
listBox.LinkedCell = “B1”;
listBox.InputRange = “sheet1!A1:A4”;
listBox.Shadow = true;
worksheet1.Cells.Rows[rowNum].Height = listBox.HeightPt;

// Save the Excel file.
workbook.Save(dir + “output.xlsx”);

My problem is that the boxes do resize with the row height in some cases. I am in a bit of a hurry so I will make the user input options i an different way for now and will take the central elements from my code and put here when I have my head i bit above water again.

Thanks for trying to help me out :slight_smile:

Hi Hans Jørgen,

The said problem should not arise because the placement type of the shape makes it independent of the cell dimensions, unless there is some bug in your current version of the API. Could you please give the latest version Aspose.Cells for .NET a try on your end to see if your can still replicate the issue? Moreover, please check the placement type of shapes by executing the code provided in my previous post against your current revision of the API and the latest one. This will give you some idea of the problem cause.

In case you still face problem with this scenario, please provide an executable sample application, when time allows. We will re-initiate the investigation to assist you further in this regard.