I've a datagridview having 4 columns. I want:
- to display all the texts inside every cell (I don't want to see any texts truncated with "...")
- that the last column fills all the remaining space
- the Horizontal and Vertical scrollbar.
Using this code:
dataGridView.ScrollBars = ScrollBars.Both;
Grid_NonAnatObj.AutoResizeColumns();
GridCol_Visibility.Width = 30;
I see all the texts inside every cell without truncations and I see both the horizontal and vertical scrollbar. When I try to add this code
Grid_NonAnatObj.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
in order to satisfy 2., the horizontal scrollbar disappear. How can I solve this problem?
It's a hack-around, but this was the best I could do to mock as closely the results you wanted.
At the very minimum, this means each column should have AutoSizeMode set to DisplayedCells. This will do the fitting for you so you don't have to guess, "Is 30 width enough? Maybe 35 just in case...". Essentially it also gives your columns a mimicked minimum width feel.
But what if your values are all small and now you have that ugly unused area on the right-hand side of the last column?
A conditional set of the last columns AutoSizeMode to Fill can fix this.
It's a little give-and-take, but when the last column is set to fill, you'll have no need of the horizontal bar. When it's set to DisplayedCells, the columns either exactly fit your width or they are larger than your width, in which case the bar will show.
CODEZ PLZ: To keep this behavior consistent through resizes, I implemented it in the dgv Resize event.
Problem: This works great, but also needs to be triggered in the form constructor to display correctly from the start.
Edit: If your cells are editable and there's a chance long data may be entered causing the dreaded ellipsis...