IgnaceMaes / MaterialSkin

Theming .NET WinForms, C# or VB.Net, to Google's Material Design Principles.
MIT License
2.86k stars 831 forks source link

Material Skin Listview : How can I get selected item Tag or Text? #184

Closed hedymhj closed 6 years ago

hedymhj commented 6 years ago

Hi, is there a way to get user selected item Tag in MaterialSkin like listbox? Like listbox1.selectedvalue or listbox1.selecteditem.tag ?? i have a label to get item tag when user clicks on MaterialSkin listview i tried : Materialskinlistview1.selecteditems.item().tag . but there's a missing index for the user selected item. Thanks.

Dutchs commented 6 years ago

SelectedItems is a collection of ListViewItem so just access the first index to get the first item from it

if (Materialskinlistview1.SelectedItems.Count == 1)
{
    var tag = Materialskinlistview1.SelectedItems[0].Tag;
}
hedymhj commented 6 years ago

Thanks. But i want the index of user selected item. If you have 7 items , when user clicks on the 2nd item a label will show "choice #2". And so. I can't guess which one user will select.

Dutchs commented 6 years ago

SelectedItems is a collection of all selected items, so if the user selects one item it will only hold that one item, in the case of MultiSelect = true it can hold multiple selected items though.

One type of use could be to listen for SelectedIndexChanged event and handle the label changes there.

are you familiar with WinForms ListView? since that has the exact same behavior in fact it inherits from it.

hedymhj commented 6 years ago

Thank you Dutchs. 👍