0

I'm working with a DataGridView, containing DataGridViewTextBoxColumns and DataGridViewComboBoxColumns. The issue is with the DropDown list of the ComboBox columns. The DropDown flow is restricted by the bounds of the screen, but my goal is for it to be restricted by bounds of the window instead.
By default, the DropDown will flow outside of the window if there is room for it; this is the issue. I need the DropDown to always stay inside the bounds of the window.

Example code for one of the ComboBox columns:

DataGridViewComboBoxColumn combo1 = new DataGridViewComboBoxColumn
{
    DataSource = Main.dsUtility.Tables["Statuses"],
    DataPropertyName = "Status",
    ValueMember = "StatusCode",
    DisplayMember = "StatusName",
    HeaderText = "Status",
    Name = "Status",
    SortMode = DataGridViewColumnSortMode.Automatic,
    FillWeight = 1.5f,
    DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing,
    DisplayIndex = 1,
    DropDownWidth = 125,
    FlatStyle = FlatStyle.System
};
dgv.Columns.Add(combo1);

Below are images that illustrate the DropDown flowing outside/inside the application window.

Shows DropDown outside of the window

Shows DropDown inside of the window

jpalella
  • 1
  • 1
  • That's a feature. – LarsTech Mar 02 '21 at 22:42
  • See followinging for partial solution. You will need to modify the code : https://www.vbforums.com/showthread.php?649155-how-to-change-the-height-of-a-combobox-in-a-datagridview – jdweng Mar 02 '21 at 22:50
  • The DropDown of a ComboBox is a Window, with its own Handle. You can get that Handle sending a [CB_GETCOMBOBOXINFO](https://docs.microsoft.com/en-us/windows/win32/controls/bumper-combobox-control-reference-messages) message to the ComboBox and `CB_GETDROPPEDCONTROLRECT`, to get its bounds. Then call `SetWindowPos()` to move it. [This is the internal procedure](https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/WinFormsUtils.cs,96) used to define the ListBox's (the DropDown) Bounds constraint, to specify a Form's Bounds instead of the Screen's. – Jimi Mar 03 '21 at 03:39

0 Answers0