I was wondering whether it is possible to remove the unused space ( the gray space ) of the DataGridView
control in C#. I have to make the DataGridView>
I have found no simple way to remove the "unused" or gray (BackgroundColor) space. However, an effective solution for me was to hide the borders of the DataGridView and to change its background color to the background of the surrounding control. In essence, the perception is that there is no more unused space.
Here is a snippet in pseudocode:
TableGridView = DataGridView()
TableGridView.Width = 0
TableGridView.Height = 0
TableGridView.AutoSize = true
TableGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
TableGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
TableGridView.BackgroundColor = SystemColors.ControlLightLight
TableGridView.BorderStyle = BorderStyle.None
I read somewhere that the AutoSize setting is not applicable, however, it did change things for me. This example suggests that the surrounding control has a background color of SystemColors.ControlLightLight, but this can be modified as required.
Please vote this up if it helped you.