Change button backcolor in custom listview item

2 posts, 0 answers
  1. Simon
    Simon avatar
    32 posts
    Member since:
    Aug 2011

    Posted 02 Nov 2016 Link to this post

    I have a listview with custom listitems that include a radButtonElement. How do I change the backcolor of the button? I've tried

        Me.MatchButtonElement.ButtonFillElement.BackColor = Color.LightGreen
        Me.MatchButtonElement.ButtonFillElement.BackColor2 = Color.LightGreen
        Me.MatchButtonElement.ButtonFillElement.BackColor3 = Color.FromArgb(122, 223, 136)
        Me.MatchButtonElement.ButtonFillElement.BackColor4 = Color.FromArgb(142, 237, 143)

    and various other approaches but nothing has worked so far.

  2. Dess | Tech Support Engineer, Sr.
    Dess | Tech Support Engineer, Sr.  avatar
    4177 posts

    Posted 03 Nov 2016 Link to this post

    Hello Simon,

    Thank you for writing.  

    Here is a sample code snippet demonstrating how to change the button element's color in a custom SimpleListViewVisualItem
    Private Sub RadForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        AddHandler Me.RadListView1.VisualItemCreating, AddressOf radListView1_VisualItemCreating
        Me.RadListView1.DataSource = Me.CustomersBindingSource
        Me.RadListView1.DisplayMember = "ContactName"
    End Sub
    Private Sub radListView1_VisualItemCreating(ByVal sender As Object, ByVal e As ListViewVisualItemCreatingEventArgs)
        If Me.RadListView1.ViewType = ListViewType.ListView Then
            e.VisualItem = New MyCustomVisualItem()
        End If
    End Sub
    Public Class MyCustomVisualItem
    Inherits SimpleListViewVisualItem
        Private buttonElement1 As RadButtonElement 
        Protected Overrides Sub CreateChildElements()
            buttonElement1= New RadButtonElement()
        End Sub
        Protected Overrides Sub SynchronizeProperties()
            Me.buttonElement1.Text = Me.Text
            Me.buttonElement1.ButtonFillElement.BackColor = Color.LightGreen
            Me.buttonElement1.ButtonFillElement.BackColor2 = Color.LightGreen
            Me.buttonElement1.ButtonFillElement.BackColor3 = Color.FromArgb(122, 223, 136)
            Me.buttonElement1.ButtonFillElement.BackColor4 = Color.FromArgb(142, 237, 143)
        End Sub
        Protected Overrides ReadOnly Property ThemeEffectiveType() As Type
                Return GetType(SimpleListViewVisualItem)
            End Get
        End Property
    End Class

    The following help article is quite useful for creating custom items in the different views:

    I hope this information helps. Should you have further questions I would be glad to help.

    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top