Reputation: 48015
This is my code:
for (int i = 0; i < 30; i++)
{
FileListView.Items.Add(new ListViewItem(new[] { "asd1", "asd2" }));
if (i < 10)
{
FileListView.Items[i].Selected = true;
}
}
FileListView.ItemDrag += new ItemDragEventHandler(FileListView_ItemDrag);
but when I Run the application, I can't see the first 10 items selected. For see them, I need to click on one of them, and they will highlights (but of course deselected immediatly, since it is like click on a single row).
How can I preselect 10 items? So a user see them selected and then can click to drag/drop to some destination...
Upvotes: 2
Views: 540
Reputation: 8214
It sounds like your ListView is not focused so when you select the items they won't highlight.
You can either focus the control before hand like this:
FileListView.Focus();
Or what's probably better is to disable the HideSelection property. This allows the ListView to display selected items when not focused.
FileListView.HideSelection = false;
Edit: With OPs new information that they need to show blue, give keyboard focus to the control once you're done:
FileListView.Select();
Upvotes: 2
Reputation: 261
The items are being selected but the control is not activated. Use FileListView.Select()
to activate the control.
Upvotes: 3
Reputation: 1718
Did you set the multiselect property with the designer or by code ?
FileListView.MultiSelect=true ;
Try also:
FileListView.Invalidate() after the loop.
Upvotes: 0