Center a button in a GridViewCommandColumn

5 posts, 1 answers
  1. QuizzBox
    QuizzBox avatar
    92 posts
    Member since:
    Jan 2011

    Posted 22 Mar 2018 Link to this post

    hey, 

    I'm using Windows 8 Theme in Telerik for Winforms 2018.1.116.40.

    With this theme, in a GridViewCommandColumn, buttons are not really cutes, the cells likes grey and user doesn't see it's a button.

    So, i want to reduce the size of buttons and center them in the cells.

    I use command lines below in CellFormatting event

    Dim button As RadButtonElement = CType(e.CellElement.Children(0), RadButtonElement)
    button.Margin = New Padding(2)

    In this case, some borders are no more visible (cf attached file).

    Have you got an idea please ?

     

    Subsidiary question : If on a condition, i only want my html text but without button i use the code in cellFormating event

    element.CommandButton.ButtonFillElement.NumberOfColors = 1
    element.CommandButton.ButtonFillElement.BackColor = Color.FromArgb(255, 255, 255, 255)
    button.BorderElement.Visibility = ElementVisibility.Hidden

    it works, but it's surely a poor code, i have tried too with 

    button.BorderElement.Visibility = ElementVisibility.Hidden

    and i don't see button and text.

    If you have a better code ;)

    Thanks for your help

    --

    Romain

     

     

  2. Dimitar
    Admin
    Dimitar avatar
    2684 posts

    Posted 23 Mar 2018 Link to this post

    Hi Jean-Marc,

    Thank you for writing

    In the first case you can set the padding of the cell:
    Private Sub RadGridView1_CellFormatting(ByVal sender As Object, ByVal e As CellFormattingEventArgs)
        Dim cell = TryCast(e.CellElement, GridCommandCellElement)
        If cell IsNot Nothing Then
            cell.Padding = New Padding(5)
        End If
     
    End Sub

    For the second one, you should hide the button and show the cell text. If you are setting this uppon a condition you need to reset the visibility value. Here is the code:
    Private Sub RadGridView1_CellFormatting(ByVal sender As Object, ByVal e As CellFormattingEventArgs)
        Dim cell = TryCast(e.CellElement, GridCommandCellElement)
        If cell IsNot Nothing Then
            If e.RowIndex Mod 2 = 0 Then
                cell.CommandButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed
                cell.Text = "Test"
            Else
                cell.CommandButton.Visibility = Telerik.WinControls.ElementVisibility.Visible
            End If
     
        End If
     
    End Sub

    Please let me know if there is something else I can help you with.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. QuizzBox
    QuizzBox avatar
    92 posts
    Member since:
    Jan 2011

    Posted 23 Mar 2018 Link to this post

    Hi Dimitar, 

    Thanks for your answer :)
    Ok for 2nd problem, but for the 1st, still problem like attach file n°1.
    On the attached file n°2, i've paint in yellow borders that i don't see.

    Regards

     

  4. Answer
    Dimitar
    Admin
    Dimitar avatar
    2684 posts

    Posted 26 Mar 2018 Link to this post

    Hi Jean,

    There is an issue with the theme in the version that you are using. To workaround it, you can set the DrawBorder property:
    Private Sub RadGridView1_CellFormatting(ByVal sender As Object, ByVal e As CellFormattingEventArgs)
        Dim cell = TryCast(e.CellElement, GridCommandCellElement)
        If cell IsNot Nothing Then
            cell.Padding = New Padding(5)
            cell.DrawBorder = True
        End If
     
    End Sub

    This is fixed in the latest version and if you upgrade the border will be visible.

    Please let me know if there is something else I can help you with. 

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. QuizzBox
    QuizzBox avatar
    92 posts
    Member since:
    Jan 2011

    Posted 26 Mar 2018 Link to this post

    Thanks, works like a charm :)
Back to Top