DataGridViewTextBoxColumn Multiline

0
1

I am not sure if this is a bug, or I am doing something wrong.

I have a DataGridView that I am binding a DataTable to and I am and trying to have the row only display a single line.

My TextBoxColumn has some rows that have strings that have new line breaks in them.

In this case I only want to display the first line.  I have set all the properties for the default cells and rows to:

WordWrap: false

Multiline: false

However I still seem to be getting multline text results.  Am I missing something or is there a multiline issue here?

Thanks,

Devin

  • You must to post comments
0
0

Hi Alaa,

Yup that works

Perfect

Devin

  • You must to post comments
0
0

Hi Devin,

You should be able to handle the Formatting event and replace the newline tokens like the following:

private void DataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
if (e.ColumnIndex == 0 && e.Value is string)
e.Value = ((string)e.Value).Replace("\r\n", "¶");
}

HTH,
Alaa

  • You must to post comments
0
0

Alaa,

I see multiline is for cell editing.

Is there any way to display a single line then? or do you have bind only a single line string?

Thanks,

Devin

  • You must to post comments
0
0

Alaa,

I see multiline is for cell editing.

Is there any way to display a single line then? or do you have bind only a single line string?

Thanks,

Devin

  • You must to post comments
0
0

Hi Frank,

Thank you for your reply, I have attached some screenshots which the desired outcome and a sample program

The screenshot “sample-desired-result.png” I created manually with only single line data rows.

The screenshot “sample-results.png” is what the sample project displays.

WordWrap and Multiline properties have been set to False, maybe I am missing something else.

Thank you for your help again,

Devin

  • You must to post comments
0
0

Hi Devin,

I wanted to clarify the properties and their functionalities:

  1. Multiline is for the Cell Editing
  2. WordWrap is to wrap the content of a string

The Newlines character have nothing to do with word wrapping, since it’s a line wrap!

HTH,
Alaa

  • You must to post comments
0
0

Hi Devin,

can you please wrap up a small compilable repro case and a description of the expected behavior?

Thanks in advance,
Frank

  • You must to post comments
Showing 7 results
Your Answer

Please first to submit.