Column widths in a DataGridView
-
2012년 5월 7일 월요일 오후 7:50
Hi
I have a requirement to have a DataGridView come up with the columns stretched across the view as if AutoSizeColumnsMode = Fill, but then after the GUI is up allow the user to resize the columns. On resizing one column, the size of all other columns should not be affected. If the total width becomes too large, the horizontal scrollbar should appear.
We've tried manually setting the sizes of the columns, but on my coworker's screen the columns are too large -- several are not visible and the scroll bar appears. When he sets the size, the columns come up short on my screen, leaving a gray area on the gridview. Neither is acceptable to QA.
I've tried also setting AutoSizeColumnsMode = Fill, then unsetting it, but the columns snap back down to a small size. After that we've gotten really hacky doing math to fill in the column widths.
I would think this is a really common problem with a standard solution, but cannot find anything the internet. Is there a suggested way to handle this situation?
Thanks
James Alan Farrell
- 이동됨 CoolDadTxMVP 2012년 5월 23일 수요일 오후 9:04 Winforms related (From:Visual C# General)
모든 응답
-
2012년 5월 7일 월요일 오후 7:53
Have you checked-out below link?
http://msdn.microsoft.com/en-us/library/74b2wakt.aspx
Regards,
Ahmed Ibrahim
SQL Server Setup Team
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you.
This can be beneficial to other community members reading the thread. -
2012년 5월 7일 월요일 오후 8:04yes.
-
2012년 5월 7일 월요일 오후 8:15
To get rid of gray area of dgv, you can set the background color of dgv to the same as its your form.
But I asctually still dont know what really is your problem. Why you want to allow user to resize columns width? I wouldn`t do that.
Mitja
-
2012년 5월 7일 월요일 오후 8:18
Because that is the requirement handed down from on high (that is, it is a customer request).
-
2012년 5월 11일 금요일 오전 6:08
Hi James,
How’s it going now? Do you have any updates about the previous issue?
Bob Shen [MSFT]
MSDN Community Support | Feedback to us
-
2012년 5월 11일 금요일 오후 6:21
What I ended up doing was setting AutoSizeColumnsMode = Fill to start, then before making the form visible I did some math to figure out the column widths, set AutoSizeColumnsMode = None, and set the sizes of each column.
Hacky, but it works (and QA is happy for the moment). Is there not a better way to accomplish this?
Thanks!
James
- 답변으로 표시됨 Bob ShenMicrosoft Contingent Staff 2012년 5월 23일 수요일 오전 9:14
- 답변으로 표시 취소됨 James Alan Farrell 2012년 5월 23일 수요일 오후 8:37
-
2012년 5월 23일 수요일 오후 8:37
I have troubles considering such a hack as answering the question. What is the proper way to achieve this same thing?
Thanks
James

