DataGridView Last Column Fill When Hiding Columns?

I understand DataGridView column 'Fill' property to make the last column 'Auto-Size'. I have a DataGridView where a user can hide columns including the last one.

Anyone know how to make the last DataGridView column 'Fill' if a user can hide columns?

Who is Participating?
Death259Connect With a Mentor Commented:
I wrote something simple that might do what you want. You will need this code portion to run everytime a column is made invisible though. If this doesn't solve your problem exactly, it should hopefully point you in the right direction.
int columnCount = dgv.Columns.Count;
int visibleColumn = 0;
for (int i = 0; i < dgv.Columns.Count; i++)
        if (!dgv.Columns[i].Visible)
        	visibleColumn = i;
if (columnCount == 1)
	dgv.Columns[visibleColumn].Width = dgv.Width;

Open in new window

All Courses

From novice to tech pro — start learning today.