Solved

Change height of combobox column in datagridview

Posted on 2014-03-04
5
1,116 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now