Solved

Change height of combobox column in datagridview

Posted on 2014-03-04
5
1,243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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