Can't set Borders in Tables and Cells

8 posts, 0 answers
  1. Manfred
    Manfred avatar
    53 posts
    Member since:
    Jan 2011

    Posted 16 Feb 2011 Link to this post

    Hi,

    got this if I try to change Borders in code behind:
    Table Kopf = new Table();
    TableBorders tb = new TableBorders();
    tb.All.Style = BorderStyle.None;
    Telerik.Windows.Documents.Model.Border.Style is readonly.

    So how can I set the Borders in code behind.
    Its really boring to search for this property to set for hours and hours :(

    Kind Regards
    Manfred
  2. Alex
    Admin
    Alex avatar
    129 posts

    Posted 16 Feb 2011 Link to this post

    Hi Manfred,

    The Border class is immutable - it cannot be modified after it is initialized. If you want to set all table borders to None, you should set the the TableBorders.All property to an new instance of the Border class. Here is an example:

    Table table = new Table();
    table.Borders.All = new Documents.Model.Border(BorderStyle.None);

    I hope this helps.

    Kind regards,
    Alex
    the Telerik team
  3. DevCraft banner
  4. Stergios
    Stergios avatar
    13 posts
    Member since:
    Nov 2012

    Posted 18 Nov 2012 Link to this post

    I've tried to use this approach to set the table borders, but the compiler "complains" that the table.Borders.All property is ReadOnly.
    Finally, how I can set properties for the table borders?

    Regards
  5. Manfred
    Manfred avatar
    53 posts
    Member since:
    Jan 2011

    Posted 19 Nov 2012 Link to this post

    Hi Stergios,

    how did you do that?
    Remember, you can only set that the way Alex described:

    wrong:
    Table Kopf = new Table();
    TableBorders tb = new TableBorders();
    tb.All.Style = BorderStyle.None;

    Right:
    Table table = new Table();
    table.Borders.All = new Documents.Model.Border(BorderStyle.None);


    Best Regards
    Manfred




  6. Stergios
    Stergios avatar
    13 posts
    Member since:
    Nov 2012

    Posted 19 Nov 2012 Link to this post

    Hello Manfred,

    Please see the attached picture. What am I missing here?

    Regards,

    Stergios
  7. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 20 Nov 2012 Link to this post

    Hello Stergios,

    The setter of the All properties of the border has been removed in the latest versions. The correct way of setting the borders of a table is either by creating a new Telerik.Windows.Documents.Model.Border instance and setting it to the table:

    private void addTableWithBorders_Click_1(object sender, RoutedEventArgs e)
    {
        RadDocument document = new RadDocument();
        Section section = new Section();
        document.Sections.Add(section);
        section.Blocks.Add(new Paragraph());
        Table table = new Table(2, 3);

        table.Borders = new TableBorders(new Border(BorderStyle.Single));

        section.Blocks.Add(table);
        this.editor.Document = document;
    }

    or using styles:
    table.StyleName = RadDocumentDefaultStyles.DefaultTableGridStyleName;

    I hope this helps.

    Kind regards,
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Stergios
    Stergios avatar
    13 posts
    Member since:
    Nov 2012

    Posted 20 Nov 2012 Link to this post

    Thank you very much.

    I prefer to use the styles approach.

    Where can I find examples of how to create and manage styles in a RadDocument?

    Regards,

    Stergios
  9. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 20 Nov 2012 Link to this post

    Hello Stergios,

    You can find information about styles in this article.

    When it comes to the names of the default styles, they are exposed as properties of RadDocumentDefaultStyles as can be seen in the previous post, which sets the StyleName of the table.

    All the best,
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft banner