DataGrid Column

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I restrict the datagrid column to display only 40 characters per line, and wrap the rest.

e.g. If the column string is 2000 characters, i would like to wrap it at 41st character. The column width should not increase more than 40 characters. Somehow its going out of the screen whenever I have tried to set it

Thanks

Ta
 
if you are talking about an ASP.NET app, realize that ultimately, all
DataGrid's are rendered as <table> ... <tr> ... <td> ... </td> ... </tr> ...
</table>

so you can write code into your page's PreRender event to look for those
<td> ... </td> tags with text that is in excess of 40 characters and
modify them (i.e. embed a <table> inside of the <td>) to have multiple lines
of only 40 characters each.


Tap said:
How can I restrict the datagrid column to display only 40 characters per line, and wrap the rest.

e.g. If the column string is 2000 characters, i would like to wrap it at
41st character. The column width should not increase more than 40
characters. Somehow its going out of the screen whenever I have tried to set
it.
 
So, There is no way it does automatically by setting DataFormatting string for the column

Could you please guide me with some code in the PreRender event

Thanks

Ta
 
Remember that ultimately, everything ASP.NET does is to render simple HTML to the clients.
The PreRender event lets you grab that rendered HTML and modify it before it actually goes to
the client...


// iterate through each row of your grid
foreach( DataGridItem dgItem in myGrid.Items )
{
// iterate through each cell of your row
foreach( TableCell tc in dgItem.Cells )
{
// iterate through each control in your cell
foreach( Control ctl in tc.Controls )
{
// check for text here and then replace
// with trimmed...
// strLong.SubString(0,40) + "<br>" +
// strLong.SubString(41,81) + "<br>" ...

}
}
}
 
Ken
Do you know if it's possible to use different font for the column header text for different column in a datagrid (winform)? I can find any info on this

Thank

Henry
 

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

Back
Top