the column size of gridview

G

Guest

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
 
G

Guest

Hi 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.HeaderAndColumnsAllRows)

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top