Tuesday, 27 August 2013

ListViewItem.ForeColor Change Doesn't Display

ListViewItem.ForeColor Change Doesn't Display

I'm using the following code to change the ForeColor of items for which a
selected action has already been performed.
internal static void grayOut(ref ListView myLV)
{
//change each selected item to gray text
//currently, multiselect is turned off, so this will only be one
item at a time
foreach (ListViewItem item in myLV.SelectedItems)
{
item.UseItemStyleForSubItems = false;
item.ForeColor = Color.Gray;
item.Font = new Font("MS Sans Serif", 10, FontStyle.Italic);
item.Selected = false;
}
myLV.Refresh();
}
I have two problems.
The property changes, but that change does not display. In other words, I
know that the ForeColor is changed to gray, because later I check to see
if it is gray when the user tries to perform a certain action. However, it
doesn't appear gray or italicized.
I'm also using the following to try and cancel a MouseDown event to keep
the item from being selected again, but it still ends up being selected:
private void lvUsers_MouseDown(object sender, MouseEventArgs e)
{
// Make sure it was a single left click, like the normal Click event
if (e.Button == MouseButtons.Left)
{
ListViewHitTestInfo htInfo = lvUsers.HitTest(e.X, e.Y);
if (htInfo.Item.ForeColor == Color.Gray)
{
return;
}
}
}
I haven't found any other method for cancelling a MouseDown event, so I'm
not sure what else to try.

No comments:

Post a Comment