Durga
Durga

Reputation: 1303

How to Auto-size cell in datagridview according to data size

I searched for Autosizing of cell but found Auto-size row and column how can I make particular cell autosize (in terms of height since column width will be fixed)according to data size of that particular cell? can it be done using some property of datagridview?

Upvotes: 1

Views: 5921

Answers (3)

Durga
Durga

Reputation: 1303

This line of code make Cell Auto-size Vertically depending on the data loaded

dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;

Upvotes: 3

Kurubaran
Kurubaran

Reputation: 8902

You can handle it through properties of DataGridView, Set the following properties. Setting follwing properties will allow the cell to expand (Vertically or horizontally) to show the full content without any truncation. These cell size expansion will result in either row or column size change where the cell exisit.

  1. AutoSizeRowsMode = AllCells
  2. AutoSizeColumnsMode = DisplayedCells

Upvotes: 0

Shyam sundar shah
Shyam sundar shah

Reputation: 2523

Use this code. It can help you

dataGridView1.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;

where 0 is column index

Upvotes: 0

Related Questions