Search code examples
c#.netcomboboxautosize

How to automatically set height of Combo Box in C# .NET?


I'm trying to fill cell in my TabView in C# .NET Framework 4.7.2 app with ComboBox as shown on the image below, but I can't figure how to fill it horizontally. Can you help me?

combo shown here (image description of a problem)


Solution

  • ComboBox height is decided by the font size of it. To change the height you have to draw the complete ComboBox yourself by setting the DrawMode property to OwnerDrawnVariable. But this also means that you are now in-charge of everything of that ComboBox and introduces far more complexity.

    Please refer to the Microsoft Learn Documentation on ComboBox.DrawMode property at https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.combobox.drawmode?view=netframework-4.7.2 which contains the code example for doing it.

    To do it automatically on Table Layout Panel after manually drawing the ComboBox you'll have to update the height each time the row height is updated. You can get the row height from TableLayoutPanel.RowStyles property.

    Related: c# - How do I set the height of a ComboBox?