Styling problem centering a CheckBox column created dynamically

4 posts, 0 answers
  1. Paul
    Paul avatar
    29 posts
    Member since:
    Aug 2011

    Posted 11 Oct 2011 Link to this post

    I have been try to center a dynamically create checkbox column with the checkbox centered. If you create it in design time, it is centered. When I create it dynamically in the Page_Load event I get the checkbox left justified. I created it as follows:

    checkBoxColumn = New TreeListCheckBoxColumn()

    treeList.Columns.Add(checkBoxColumn)

    checkBoxColumn.DataField = "Accessibility"

    checkBoxColumn.UniqueName = "Accessibility"

    checkBoxColumn.HeaderText = "Accessibility"

    checkBoxColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center

     

    It works, just not centered. Any ideas as to why I cannot center the checkbox?

    Thanks,

    Paul
  2. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 11 Oct 2011 Link to this post

    Hi Paul,

     
    If you want to center the CheckBox in a column you should define a cell style and set the HorizontalContentAlignment property to Center:

    <UserControl.Resources>
       <Style x:Key="style1" TargetType="telerik:GridViewCell">
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
       </Style>
    </UserControl.Resources>

    Finally you may set this style in code-behind to the column as shown below: 

    column.CellStyle=this.Resources["style1"] as Style;

    Best wishes,
    Vanya Pavlova
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Paul
    Paul avatar
    29 posts
    Member since:
    Aug 2011

    Posted 12 Oct 2011 Link to this post

    My code behind is in VB. I tried the following:

     

    Dim checkBoxColumn As New TreeListCheckBoxColumn()

    tcConfig.Columns.Add(checkBoxColumn)

    checkBoxColumn.DataField = "Accessibility"

    checkBoxColumn.UniqueName = "Accessibility"

    checkBoxColumn.HeaderText = "Accessibility"

    checkBoxColumn.CellStyle = Resources("style1")

     

    I am getting an error:

    ‘CellStyle’ is not a member of ‘Telerik.Web.UI.TreeListCheckBoxColumn’.


    I then tried,


    checkBoxColumn.ItemStyle.CssClass = Resources("style1")

     


    with the user control resources in the aspx page and also in the Web.config file. Either way ‘Resources’ was not found.

  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 12 Oct 2011 Link to this post

    Hi,

     This forum is for our Silverlight products only. Please post your questions in the relevant category!

    Greetings,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top