Wednesday, March 28, 2012

the column size of gridview

hi all:

the one of the column of gridview got multiple line data to be shown , so
how do i deal with it? what i am thinking about is using template field
instead of the boundfield. is that other solution out there?

Cheers

NickHi Nick,

You can solve this problem with the DataGridView.AutoSizeColumns() method,
with one of the values from the DataGridViewAutoSizeColumnCriteria
enumeration.
You can choose to size columns based on the width of header text, the
currently displayed rows, or all the rows in the table.

The following code snippet resize columns based on the width of the largest
piece of text in a header or one of the rows for this column.
DataGridView1.AutoSizeColumns( _
DataGridViewAutoSizeColumnCriteria.HeaderAndRows)

Please note that this method needs to be invoked after you bind the data or
it won't have any effect. You might also want to use it after user editing
(perhaps in response to an event like DataGridView.CellValueChanged).

Rather than widening columns to fit, you can change the row size. By
default, the text in a column will wrap over multiple lines.

If you use the DataGridView.AutoSizeRows() method, the row will be
heightened to fit the content.

Before you use this method, you might want to widen the column size,
particularly if you have a field that contains a large amount of text. For
example, the following code snippet quadruples the size of the Description
column, and then resizes
the rows to accommodate the content.

DataGridView.Columns("Description").Width *= 4
DataGridView.AutoSizeRows( _
DataGridViewAutoSizeRowsMode.HeaderAndColumnsAllRo ws)

Pls let me know whether this helps you
Thanks & Regards,
Sundar Narasimman

"Nick" wrote:

Quote:

Originally Posted by

hi all:
>
the one of the column of gridview got multiple line data to be shown , so
how do i deal with it? what i am thinking about is using template field
instead of the boundfield. is that other solution out there?
>
Cheers
>
Nick

0 comments:

Post a Comment