Wrapping text in a DataGrid Cell

Discussion in 'Microsoft C# .NET' started by Randy, Oct 1, 2003.

  1. Randy

    Randy Guest

    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
     
    Randy, Oct 1, 2003
    #1
    1. Advertisements

  2. Hi Randy,

    When a cell is not being edited, its conent is painted with the
    corresponding DataGridColumnStyle'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.DataGridTextBoxColumn 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
    http://x-unity.miik.com.ua/teststudio.aspx
    Bring the power of unit testing to VS .NET IDE

    "Randy" <> wrote in message
    news:...
    > 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], Oct 2, 2003
    #2
    1. Advertisements

  3. 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" <> wrote in message
    news:...
    > 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
    >
    >
     
    Michael Earls, Oct 3, 2003
    #3
  4. Randy

    Randy Guest

    Thanks for the help...Have a good day

    "Randy" <> wrote in message
    news:...
    > 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
    >
    >
     
    Randy, Oct 6, 2003
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Buddy

    Stop Labels Wrapping Text

    Buddy, Sep 12, 2003, in forum: Microsoft C# .NET
    Replies:
    1
    Views:
    397
    Jeffrey Tan[MSFT]
    Sep 12, 2003
  2. abc

    How to prevent Label text from wrapping?

    abc, Jan 7, 2004, in forum: Microsoft C# .NET
    Replies:
    4
    Views:
    354
    Jeffrey Tan[MSFT]
    Jan 12, 2004
  3. Guest

    Wrapping text in DataGridTextBoxColumn

    Guest, May 17, 2004, in forum: Microsoft C# .NET
    Replies:
    1
    Views:
    1,146
    Dmitriy Lapshin [C# / .NET MVP]
    May 17, 2004
  4. Adrian

    Text wrapping question

    Adrian, Oct 8, 2004, in forum: Microsoft C# .NET
    Replies:
    0
    Views:
    157
    Adrian
    Oct 8, 2004
  5. wrapping text in datagrid

    , Nov 11, 2007, in forum: Microsoft C# .NET
    Replies:
    1
    Views:
    276
    Alexey Smirnov
    Nov 12, 2007
Loading...

Share This Page