This is a migrated thread and some comments may be shown as answers.

Change button backcolor in custom listview item

1 Answer 130 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 02 Nov 2016, 05:07 AM

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.

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Nov 2016, 10:37 AM
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.
Tags
ListView
Asked by
Simon
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or