Solved

Change height of combobox column in datagridview

Posted on 2014-03-04
5
1,199 Views
Last Modified: 2014-03-06
I can change the height of a normal combobox

I can change the row height of a row in a datagridview

But how do i change the height of a combobox column which is in a datagridview?
0
Comment
Question by:SweetingA
  • 3
  • 2
5 Comments
 
LVL 40
ID: 39905734
By height, I suppose that you are meaning the number of lines to display, because the Height if fixed in the standard ComboBox.

You can change the number of elements in a DataGridViewComboBoxColumn by setting the column's MaxDropDownItems property.
0
 

Author Comment

by:SweetingA
ID: 39907743
No i mean the height (thickness)

I have changed the row height of the datagrid but the combo box thickness is now less than half the row thickness

I can't click on the combobox to change its properties because i added it in code so its not visible to click on, therefore i need to change its size in code

Dim cbo As New DataGridViewComboBoxColumn()
DataGridView1.Columns.Add(cbo)

Thanks
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 39907826
Even if you could click on the ComboBox, you would not be able to change it's height, because there is no Height or Size property on a DataGridViewComboBoxColumn. You can change the height of the Row, but the ComboBox has a predefined and fixed height, just as a CheckBox has a fixed size.

The only way to change it is by changing the Font, but since the only place where you can change the Font is at the grid level, that would not make any sense.

As far as I know, this is also the only way to change the Height on a normal ComboBox.

And it makes sense. Since a ComboBox cannot display multiple lines for a given item, changing its height without changing the Font will leave you with a useless blank in the ComboBox.

I understand that you might want to change the height in a grid if you changed the row height, but Microsoft did not seem to think it was useful to change the height of the ComboBox even in that situation.

If you really want to do it, I think that you will be stuck with one for the 2 following solutions.

Inherits from the DataGridViewComboBoxColumn class and create your own class, where you override the Paint event and draw the thing yourself. Good luck with that one.

Create the column as a TextBoxColumn. When the user enter a cell in your column, temporarily display a standard ComboBox over it, and set its selection to the content of the cell. When the user gets out of the ComboBox, copy the new selection in the Cell and make the ComboBox invisible until it is needed again.
0
 

Author Comment

by:SweetingA
ID: 39908906
ok james, thanks for the info

I do understand why its not available, i was just attempting to keep things looking pretty

Actually it doesn't look that bad.
0
 

Author Closing Comment

by:SweetingA
ID: 39908908
although it never provided a solution, the problem very well explained
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question