DatagridView: Remove unused space?

前端 未结 8 1238
-上瘾入骨i
-上瘾入骨i 2021-01-11 15:25

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

8条回答
  •  粉色の甜心
    2021-01-11 16:06

    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.

提交回复
热议问题