MaterialSkin Listview Listviewitem style

MaterialSkin Listview Listviewitem style

  • 139 Views
  • Last Post 13 July 2018
Emre posted this 12 July 2018

hi everyone.

I tried to use IgnaceMaes/MaterialSkin

Default .net ListView control and its ListViewItems can be stylized easily but MaterialSkin's Listview.

Q: How do you set -for ex: backcolor- of a ListViewItem of MaterialSkin's Listview?
Or How do dou set specific ListViewItem of Listview as Selected or Focused?

thanks

Order By: Standard | Newest | Votes
jack posted this 13 July 2018

I think there is a problem when customizing the ListView control. I'm trying but not in effect

public class AccountInfo
{
    public string AccountType { get; set; }
    public int Balance { get; set; }
    public int Rating { get; set; }
}

Generate dummy data

public List<AccountInfo> GetAccounts()
{
    List<AccountInfo> accounts = new List<AccountInfo>();
    for (int i = 0; i < 2000; i++)
    {
        accounts.Add(new AccountInfo
        {
            AccountType = i % 3 == 0 ? "Good" : "Bad",
            Balance = i,
            Rating = i * 2
        });
    }
    return accounts;
}

Add data to the MaterialListView control but has no effect, similarly set the backcolor for the ListView

private void frmMaterial_Load(object sender, EventArgs e)
{
    List<AccountInfo> accounts = GetAccounts();
    int row = 0;
    foreach (var acc in accounts)
    {
        ListViewItem item = new ListViewItem(new string[] { acc.AccountType, acc.Balance.ToString(), acc.Rating.ToString() });
        item.BackColor = row % 2 == 0 ? Color.White : Color.Red;
        materialListView1.Items.Add(item);
        row++;
    }
}
Emre posted this 13 July 2018

Thanks for reply.

OnDrawItem

I found that this guy has overrided OnDrawItem event and set almost all of the items properties to specific styles as shown below.

//always draw default background
g.FillRectangle(new SolidBrush(SkinManager.GetApplicationBackgroundColor()), new Rectangle(new Point(e.Bounds.X, 0), e.Bounds.Size));

But interesting thing is when i tried to override OnDrawItem it's never been raised. Idk what do i miss.

Close