How to set property isEnabled in each subitem butt

2019-08-26 13:28发布

问题:

I have listview. In this listview I have listview.item that contains button. I bind my listview to some datasource, so I have many buttons. How to disable all of this buttons?

http://pastebin.com/6MFDfX9S

回答1:

Looking at your code, besides binding to "Title", "Date", "DownloadedOrNot" and "Info" you can add another property and bind that to the IsEnable property of the buttons, like "IsEnable.

If you need to change the value of this property you can always traverse your ListView Items like this:

foreach (var item in listview.Items)
{
    (item as your_object).IsEnable = false;
}


回答2:

If you have lots of buttons.. Use LINQ insted.

listview.Items.All(item =>{(your_obj)item.IsEnable=false; return true});