Wrapping text in a DataGrid Cell

  • Thread starter Thread starter Randy
  • Start date Start date
R

Randy

Hello,
How would this be done? I've looked at the datagrid itself and also the
tableStyle and can't find out how to make text wrap in a cell.
Thanks
 
Hi Randy,

When a cell is not being edited, its conent is painted with the
corresponding DataGridColumnStyle's Paint method (there are several
overloads). When it is being edited, cell appearence is in hands of a user
control used to edit the cell contents - most likely this will be a TextBox.

So what you need is inheriting from
System.Windows.Forms.DataGridTextBoxColumn and overriding its Paint method
to enable wrapping. You might also need to overload column style methods
responsible for calculating the row height - the grid won't be able to
adjust the row height upon double-click between row headers otherwise. To
make the text wrap during editing, you will need to tweak the hosted
TextBox - probably it should be switched to the MultiLine mode, but I am not
so sure here.
 
Hi Randy,

The best way to solve any layout problem is to use CSS.

Set the CSS class of the cell to a CSS class that has the following
definition:

..nowrap{
white-space: nowrap;
}


or, you could set the inline style attribute to style="white-space:
nowrap;", but this is not supported in older Netscape browsers.

Look at the cell columns properties and set the class there if at all
possible.

Michael Earls
 
Back
Top