I have a ListView control in .NET Winforms containing filenames from a directory. When first displaying the control, I populate the listview, then programmatically select the first item in the list thusly:
if (lvwFiles.Items.Count > 0)
{
ListViewItem firstItem = lvwFiles.Items[0];
firstItem.Selected = true;
}
This works fine, except that the first item in the list should be visually highlighted (reverse-highlighted?) to indicate to the user that it’s the one selected, as happens if the user then clicks one of the items.
It seems like a dumb question, but I’ve looked around on Stackoverflow and elsehwere and don’t see an obvious answer. Is there an easy way to make this happen via setting a property or something similar?
Change the
HideSelectionproperty to false in the designer (or through code). Doing that will allow the selected item to show even when the control does not have focus.