Add Adaptive AutoSizeColumnsMode to DataGridView #15046
Unanswered
AssistoraNova
asked this question in
Ideas
Replies: 1 comment 1 reply
|
@AssistoraNova if you were going to do that today manually where would the code go. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Currently, DataGridView only supports static sizing modes (AllCells, Fill, etc.).
Proposal: Add a new Adaptive mode that first applies AllCells, then checks the total width. If the columns don’t fill the grid, it automatically switches to Fill.
Example usage:
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Adaptive;
This would improve usability, save developer time, and provide a responsive layout out-of-the-box.
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Adaptive;var dgv =DataGridView1; dgv.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); int totalWidth = dgv.Columns.Cast<DataGridViewColumn>().Sum(c => c.Width); dgv.AutoSizeColumnsMode = totalWidth < dgv.ClientSize.Width ? DataGridViewAutoSizeColumnsMode.Fill : DataGridViewAutoSizeColumnsMode.AllCells;This would improve usability, save developer time, and provide a responsive layout out‑of‑the‑box.
All reactions