VB.NET - Dynamically adjusting column widths in datagrid
Posted on 2007-08-12
I'm creating an application in VB.NET. I've created a datagrid to display records from my database.
This datagrid will actually be showing data from different tables, depending on table the user wishes to view, so i'm creating and configuring the data adapter and dataset via code and then refreshing the datagrid.
I have a function which runs every time a user selects to display a table on the datagrid. It's a simple function that dynamically creates the datagridtextcolumns based on the number of columns in the table in the dataset. So far, the program works well.
However, the only part i'm having a problem with is the column width. I need to dynamically be able to adjust the width of the colum for each datagridtextcolumn, to fit the longest entry in that column. Any ideas on how this can be accomplished?