bill5967
bill5967

Reputation: 59

C# ObjectListView BackColor (Windows Forms)

So I want to set a specific background color of an entire row.

I already achieved this by implementing the following code:

foreach(var model in modelList)
            objectListView1.BackColor = model.RowColor;
            objectListView1.AddObject(model);

This works as intended. It will iterate through my model list and add the Row Color assigned to it. So my OLV has 2 whole rows highlighted.

The issue lies when I hover my mouse over the row, it will go back to white. It seems like the OLV is refreshing when I preform an action and resetting the BackColor to the default.

How can I prevent this from happening?

Upvotes: 1

Views: 183

Answers (1)

Rev
Rev

Reputation: 6112

If you want to permanently set the row color depending on the model.RowColor use the FormatRow event.

Then you can do something like this:

private void olv1_FormatRow(object sender, FormatRowEventArgs e) {
    e.Item.BackColor = model.RowColor;
}   

Upvotes: 1

Related Questions