multiline datagridview cells?

In beta1, datagridview cells could contain display multiline data by default. In beta2, the data is shown on a single line with some control characters.

(1) Can I set the cells to display multiline

(2) Can I replace the control characters with something else (eg a double space) to make it look a little more professional

Thanks


Answer this question

multiline datagridview cells?

  • MrMojoRisin

    You probably need to set your AutoSizeRowsMode property on the column in question... to AllCells, for example.

    -Andrew



  • Krivahn

    You can call AutoResizeRow and pass in the rowindex or you can set the AutoSizeRowsMode which will auto size the heights of all rows.

    Hope this helps,
    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"

  • JoeSox

    Ok, I have given up on the multline cells mainly due to the large performance hit when using autoresize rows and columns and wrapmode=true.

    Instead, I would like to use a single line, but replace any crlf with a space. Alternatively, have just the first line followed by ...

    Is there a simple way to do this

    (The datagridview is readonly)

    Thanks


  • sqltechlead

    You're correct that this has changed. There was a bug in the behavior that caused us to change this to where we wrap the text anytime it doesn't fit.

    Regarding auto size behavior. The DataGridView code attempts to create a good offset of width to height but it does not do what you request (about displaying all on one line or multiple lines only when there is a CRLF).

    You can plug in your own calculations for autosize by inheriting from DataGridViewCell::GetPreferredSize().

    Hope this helps!
    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"

  • alpha1105omega

    You can handle the CellFormatting event and dynamically replace your CRLF with spaces.

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"

  • George Jackson

    You need to set the WrapMode to True to enable multiline DGV cells. This is a change from Beta1 (it defaulted to true in Beta1 and is now false.)

    thanks,
    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"

  • VB.IS.NOT.PYTHON

    Yes - Derive from the DataGridViewTextBoxCell class and override the GetPreferredSize method. You will also need to override the Paint method to paint your text using different TextRenderer flags.

    You can manually add your custom cell to a row via the Row.Cells collection:



    DataGridViewRow myDataGridViewRow = new DataGridViewRow();
    myDataGridViewRow.Cells.Add(mycustomTextboxCell);

     

    You can also create a custom column type so you can get design time support. See this post for an example of a custom column:http://www.windowsforms.net/Forums/ShowPost.aspx tabIndex=1&tabId=41&PostID=15227

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"


  • SuperRock

    not really sure about how to do that.

    Does that mean that I create a derived datagridviewcell and ovverride the getpreferredsize method

    Do I then have to use the dervied datagridviewcell instead of the original one and if so, how do I go about this

    Thanks

  • Scott Myers

    I now see that setting the WrapMode property does not just allow multiline text to be displayed as multiline. Rather, it wraps any text that it too long to fit in the cell.

    When combined with autosized row heights and column widths, the results are not what I desire. I want to have the columns resize to accomodate the widest single line for that column, and the row height to resize to accomodate the maximum number of lines in that row. Is this possible

    In other words, I only want to display text on a new line if there is a CRLF in the text. Otherwise, I want the column to resize to the width (or add ...).

    I believe this was possible in previous releases, but cannot see how to do it now.

    Thanks

  • cool-net

    For me it is the contrary case. I would like the datagridview to wrap not only for CRLF, but also for any text that is too long to fit in the cell., but it only wraps the CRLF. (I set the autosizecolumnmode is Fill and the autosizerowmode is All Cells) Anyone can help

  • Alec Cozens

    this is a real problem. multiline text looks so ugly with the control characters dispalyed as black rectanges. There must be a way surely!!!
  • Mike Duke

    anyone
  • guiticom1304

    i have set the WrapMode is True,but it worked just in edit mode,when a cell is not in edit mode,it appear no wrapped.why
  • ErikG

    great thanks.

    Now, is there a way to autosize the row heights to the maximum size of cell content

    For example, 3 cells are single-line, 1 cell is double-line, so set row height OF THAT row to accommodate the double-line data. (and repeat for each row, so each row has a different height - similar to the column autosizing)

  • multiline datagridview cells?