Cell spacing?

5 posts, 1 answers
  1. Per
    Per avatar
    120 posts
    Member since:
    Jan 2008

    Posted 27 May 2009 Link to this post


    I have a radgrid with the cell text alignment, in the first column, set to middle left.
    The text in the cell (and the headertext) is to close to the edge of the radgrid.

    The text in the cell looks missplaced since the is a 5px margin both above and below the text, but to the left there is none.

    Is it possible to add a spacing to the left of the text (both headertext and cell), that is equal to the spacing above and below the text?
    Can it be done by using FormatString?

    Per Bornsjo

  2. Answer
    Jack avatar
    2333 posts

    Posted 27 May 2009 Link to this post

    Hi Per,

    The best option in this case is to set a left padding. This can be done when handling ViewCellFormatting to affect also the header cell. Consider the following sample:

    void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e) 
        e.CellElement.Padding = new Padding(5, 0, 0, 0);     

    I hope this helps. If you have further questions, I will be glad to answer them.

    Best wishes,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Per
    Per avatar
    120 posts
    Member since:
    Jan 2008

    Posted 27 May 2009 Link to this post


    Thanks for your quick reply.

    Just what I was looking for :)

    Per Bornsjo
  4. Martin
    Martin avatar
    28 posts
    Member since:
    Nov 2019

    Posted 05 Aug 2020 in reply to Jack Link to this post

    Is it possible to do this directly from the view and not use any code-behind?
  5. Nadya
    Nadya avatar
    502 posts

    Posted 05 Aug 2020 Link to this post

    Hello, Martin,

    Customizing the cell's look is possible at run time in the code. Since RadGridView uses UI virtualization it is suitable to use formatting events such as CellFormatting/ViewCellFormatting events. Additional information is available here: https://docs.telerik.com/devtools/winforms/controls/gridview/cells/formatting-cells

    Another approach is to modify directly the theme that you are using with Visual Style Builder tool. You can read more details about using the VSB and modifying themes here:

    1.     Loading predefined themes
    2.     Working with Repository Items
    3.     Saving and Loading Theme Files
    4.     Loading Themes from an External File
    5.     Loading Themes from a Resource
    6.     Applying Theme to a Control
    7.     https://www.telerik.com/videos/winforms/what-is-new-in-visual-style-builder-for-q1-2010

    I hope this information is useful. Should you have other questions do not hesitate to ask.

    Progress Telerik

Back to Top