Try removing the libraryExplorer.selectedItems.Clear( ) line.
This should also solve the problem of MultiSelect, which apparently does not have effect.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello there. I have the following code:
private void folderView_SelectedIndexChanged(object sender, EventArgs e) {
libraryExplorer.selectedItems.Clear();
libraryExplorer.selectedItems = folderView.SelectedItems;
if (folderView.SelectedItems.Count == 1)
toolStrip.Items[1].Enabled = true;
else
toolStrip.Items[1].Enabled = false;
}
What it does, is it enables the "Rename folder" button in a toolStrip if only one item is selected, if not, it disables it. The libraryExplorer
is a class I created with functions that helps with other stuff, so that doesn't matter.
My problem is, that folderView.SelectedItems.Count
always returns 0.
I am not programmatically setting any selected items. You can only select stuff by clicking and the ListView has multiSelect set to true. (Although that's another problem I have to tackle, multiSelect doesn't work even if it is true, holding control doesn't do anything)
It could be that I am misunderstanding how a ListView works, and I would be extremely happy if someone enlightened me. :)
With regards,
Alvin.
Try removing the libraryExplorer.selectedItems.Clear( ) line.
This should also solve the problem of MultiSelect, which apparently does not have effect.
Make sure MultiSelect is enabled for folderView
.folderView.MultiSelect = true;
I have come across this before, don't try and test for the number of selected items in the SelectedIndexChanged event use the ItemSelectionChanged event.