• 0

DataGridView Control & Embedded Comboboxes


Question

I've been pulling my hair out on this one and it's -really- starting to get up my nose now, so I'm hoping someone here can possibly answer this question.

 

Have a DataGridView control. On this grid are many rows and columns, all data bound. Some of these are bound to ComboBoxColumns which have their own datasources as per the normal way. All this works fine and I'm happy with that.  However, I now need to show 2 lines of data in each row, due to having run out of columns and the client needing to see this data at a glance, forcing me to double some columns up. We used this technique just fine back in the old VB6 days on the flexgrid, and it works just fine in the DataGridView too.

 

What does NOT work fine, is the bloody combobox.  It still shows the data as I want it, but now that the row is higher, the combobox is still only the height of a single line of data, so sits at the top of the cell, a box within a box, looking bloody stupid. ARGH!

 

Now, I know full well that the height of a combobox cannot be set manually. Microsoft, in their infinite wisdom, decided that its height shall henceforce be set ONLY by the font size, and they will be forever cursed for such a dumbassed decision, but I will not do that here.  It  looks bloody stupid to have one cell of data a different font size to the rest of it, so not happening.  To get around this, you can instead just hit the API directly, and use SendMessage to change the height of a combo.  

 

This works great and I've used it many times in the past.  However, it doesn't work on a DataGridViewComboBoxEditingControl.  This control, which derives from the ComboBox base class, doesn't seemingly work with SendMessage due to it being inherited, so the call to SendMessage doesn't do diddly squat. It doesn't error, but it doesn't work either.

 

This is the call:     

SendMessage(comboBoxHandle, CB_SETITEMHEIGHT, -1, comboBoxDesiredHeight);

Do that to a combobox, and it works perfectly; you get a nice tall combobox just how you want it.

 

NOTE: What I mean here is the actual height of the combo itself, not the items in the dropdown, not the dropdown portion either. I mean the textbox portion of the control with the dropdown button in it, including the height of that button as well.

 

SO.. my question is, does anyone know if it's possible to do this to the DataGridViewComboBoxEditingControl as it currently is?  I -could- write my own editing control, it's not hard, but I'd much rather override what's already there as we're trying not to write our own controls where possible...

 

PS: If you know how to do the same to that bloody DateTimePicker control as well, I'll buy you a case of beer! ;) 

 

It really does boggle my mind that MS never thought to consider someone might want a grid row larger than a single row of text...

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

This topic is now closed to further replies.