Monday, April 4, 2016

How to wrap text in a DataGridViewColumn

Given that you have data such as comments/notes/description/address that would comprise at least hundreds of characters and you want to show them on the DataGridView control, you will notice that the text is concatenated and replaced with ellipses.

In order to achieve wrapping of text in a DataGridView cell, I achieved it using these steps.
1. Change the WrapMode value to True of a DataGridViewTextBoxColumn's DefaultCellStyle. 2. In my DataBindingComplete event of the DataGridView, set the AutoSizeRowsMode of the DataGridView to AllCells.
C# Code
private void dgvFormat_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
 dgvFormat.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

That's it.. :-)


Post a Comment