I have a problem with datagridview in Winform.
I have a list of table names in the left pane. When I click on a table, I show the contents of the table in the right pane. I display the data in a datagridview, getting the data and assigning a datasource to dgv.
I set the following property in dgv.
dgTemp.Dock = DockStyle.Fill; dgTemp.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; dgTemp.AutoSize = true; dgTemp.DefaultCellStyle.WrapMode = DataGridViewTriState.True; dgTemp.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; dgTemp.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; dgTemp.ReadOnly = true; dgTemp.AutoGenerateColumns = true; dgTemp.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dgTemp.AllowUserToAddRows = false;
My problem: there can be any number of columns in the Datasource that I assign to dgv. So if the number of columns is very small (say, 1 or 2), the dgv size is very small, and the empty space on the right side gives a very ugly look. I cannot use auto autosizecolumnmode to fill , because when there are more columns, all columns become squeezed and expanding columns prevent me from scrolling at the bottom
therefore my requirement
- All space in the datagridview must be filled. (should cover the entire area)
- When a larger column appears, a scroll will appear to make it look better.
Are there any events or properties that I can use?
Thanks pending.
source share