Change button backcolor in custom listview item

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

    Posted 02 Nov 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
    Admin
    Dess avatar
    1601 posts

    Posted 03 Nov 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
        Me.CustomersTableAdapter.Fill(Me.NwindDataSet.Customers)
     
        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()
            MyBase.CreateChildElements()
            buttonElement1= New RadButtonElement()
            Me.Children.Add(Me.buttonElement1)
        End Sub
        Protected Overrides Sub SynchronizeProperties()
            MyBase.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
            Get
                Return GetType(SimpleListViewVisualItem)
            End Get
        End Property
    End Class

    The following help article is quite useful for creating custom items in the different views: http://docs.telerik.com/devtools/winforms/listview/custom-items

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

    Regards,
    Dess
    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.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top