Wrapping text in DataGridTextBoxColumn

G

Guest

I have a datagrid column which I want to expand when i type in some text. Initially I tried increasing the column width on the key down event of that DataGridTextBoxColumn, but it didn't work out as expected. Now, I am trying to increase the height of the row to make it as a multiline column.

private DataGridTextBoxColumn dgcComments
dgcComments = new DataGridTextBoxColumn()
dgcComments.TextBox.Multiline = true
dgcComments.TextBox.AcceptsReturn = true
dgcComments.TextBox.WordWrap = true

I am able to increase the row height, but the text is not wrapping to fit the row height. The text keeps scrolling to the left in a single line. I have set the WordWrap property to True and Multiline property to True, but it doesn't seem to work. Another thing that I tried is to display a vertical scroll bar, but that also fails to meet the reqmt. Anybody has any idea how to wrap text in a text box column of datagrid
Sangeetha
 
D

Dmitriy Lapshin [C# / .NET MVP]

The TextBox itself is only used when a cell in the column is being edited.
For displaying data, the PaintText method of the DataGridTextBoxColumn is
used. Therefore, the first thing to try is to start editing some cell and to
ensure the hosted TextBox instance is indeed multi-line. Then, override the
PaintText method (or the Paint method if the former is not virtual) and
provide your own drawing code which will allow for line wraps.

Sangeetha said:
I have a datagrid column which I want to expand when i type in some text.
Initially I tried increasing the column width on the key down event of that
DataGridTextBoxColumn, but it didn't work out as expected. Now, I am trying
to increase the height of the row to make it as a multiline column.
private DataGridTextBoxColumn dgcComments;
dgcComments = new DataGridTextBoxColumn();
dgcComments.TextBox.Multiline = true;
dgcComments.TextBox.AcceptsReturn = true;
dgcComments.TextBox.WordWrap = true;

I am able to increase the row height, but the text is not wrapping to fit
the row height. The text keeps scrolling to the left in a single line. I
have set the WordWrap property to True and Multiline property to True, but
it doesn't seem to work. Another thing that I tried is to display a vertical
scroll bar, but that also fails to meet the reqmt. Anybody has any idea how
to wrap text in a text box column of datagrid ?
 

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

Top