Wrapping text in a DataGrid Cell

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Randy

    Wrapping text in a DataGrid Cell

    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


  • Dmitriy Lapshin [C# / .NET MVP]

    #2
    Re: Wrapping text in a DataGrid Cell

    Hi Randy,

    When a cell is not being edited, its conent is painted with the
    corresponding DataGridColumnS tyle'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.DataGridT extBoxColumn 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.

    --
    Dmitriy Lapshin [C# / .NET MVP]
    X-Unity Test Studio

    Bring the power of unit testing to VS .NET IDE

    "Randy" <temp@temp.co m> wrote in message
    news:uH4wTsFiDH A.2504@TK2MSFTN GP09.phx.gbl...[color=blue]
    > 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
    >
    >[/color]

    Comment

    • Michael Earls

      #3
      Re: Wrapping text in a DataGrid Cell

      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



      "Randy" <temp@temp.co m> wrote in message
      news:uH4wTsFiDH A.2504@TK2MSFTN GP09.phx.gbl...[color=blue]
      > 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
      >
      >[/color]


      Comment

      • Randy

        #4
        Re: Wrapping text in a DataGrid Cell

        Thanks for the help...Have a good day

        "Randy" <temp@temp.co m> wrote in message
        news:uH4wTsFiDH A.2504@TK2MSFTN GP09.phx.gbl...[color=blue]
        > 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
        >
        >[/color]


        Comment

        Working...