• 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...

1 answer to this question

Recommended Posts

This topic is now closed to further replies.
  • Posts

    • Russia is based in Cyprus. AdGuard is about as Russian as Telegram is.
    • Pixel Recall anyone? Or LiveRecall, OpenRecall or WindRecorder? Someone, somewhere wants your data.
    • HP 15.6-inch laptop is 20 percent off for students and everyday users by Paul Hill If you’re a student or casual user, this HP 15.6-inch laptop (model 15-fc0499nr) may be a good fit for you, as it has been discounted by 20% from $499.99 to just $399.99. It’s not a cutting-edge machine, but at this price, its core specs are solid, making it a great back-to-school option. It’s worth pointing out that this laptop carries an Amazon’s Choice badge and has over 1,000 purchases in just the last month, highlighting its popularity. Next, we'll discuss the specifications, followed by a buying link if you're interested in purchasing it. Powering this laptop is an AMD Ryzen 5 7520U processor, 8GB of LPDDR5 RAM, and a 512GB PCIe NVMe M.2 SSD. These aren’t the highest specs ever, but for everyday tasks, you should get your tasks done efficiently. The inclusion of the SSD means your system will boot quickly and your apps will launch fast, even if launching for the first time. It has a 15.6-inch HD touchscreen display, which is a key feature and a pretty big deal at this price point. If you find yourself with a task where a mouse isn’t suited, just touch the screen instead; it seems pretty useful for graphics work if you need to do some. One shortcoming of this device is that it uses integrated AMD Radeon Graphics, which is enough for casual entertainment and light creative work, but don’t expect to be playing heavy games. As for the operating system, this laptop ships with Windows 11 Home. It’s worth pointing out here that this is not a Copilot+ PC, so it will be missing Recall and other AI features, but it does have a Copilot key. This laptop is great if you’re going to be taking it to school or college, as it’s lightweight at just 3.52 lbs (1.6kg). It also has decent connectivity with 1 USB Type-C (data transfer only), 2 USB Type-A, 1 HDMI 1.4b, and a headphone/microphone combo jack. It also features Wi-Fi 6 and Bluetooth 5.3 for modern connectivity. Other notable features include the HP True Vision 720p HD camera with noise reduction for video calls and a camera privacy shutter. The laptop also has a long-lasting battery life of up to 12 hours and supports Fast Charge, which gets you to 50% in 45 minutes. If you’re convinced by this solid entry-level laptop, check out the buying link below: HP 15.6-inch laptop (model 15-fc0499nr): $399.99 (Amazon US) / MSRP $499.99 This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
    • Install a cheap Chinese clone of Adguard and then take support from call center to restore to Windows XP.
    • Does the job, although it can't run windows 11 officially. Currently running Windows 10 modded with ReviOS
  • Recent Achievements

    • Dedicated
      Snake Doc earned a badge
      Dedicated
    • One Month Later
      Philsl earned a badge
      One Month Later
    • One Year In
      armandointerior640 earned a badge
      One Year In
    • One Month Later
      armandointerior640 earned a badge
      One Month Later
    • Week One Done
      Itbob513626 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      614
    2. 2
      ATLien_0
      236
    3. 3
      Xenon
      155
    4. 4
      +FloatingFatMan
      123
    5. 5
      Michael Scrip
      116
  • Tell a friend

    Love Neowin? Tell a friend!