如何在选中复选框时选择列表框中的所有项目? [英] How do I select all items in a listbox on checkbox checked?

查看:26
本文介绍了如何在选中复选框时选择列表框中的所有项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击 CheckBox 时,我需要选择 ListBox 中的所有项目.是否可以使用一行代码选择 ListBox 中的所有项目?还是我必须遍历所有项目并将每个项目的 selected 设置为 true?

I need to select all items in a ListBox when a CheckBox is clicked. Is it possible to select all items in the ListBox using a single line of code? Or will I have to loop through all items and set selected to true for each one of them?

推荐答案

我认为你必须在这里循环.一次选择所有项目是一个非常具体(并且可能很少见)的用例,开箱即用地提供该功能是没有意义的.此外,无论如何,循环只是两行代码.

I think you have to loop here. Selecting all items at once is a pretty specific (and probably rare) use case where it simply makes no sense to offer that functionality out of the box. Furthermore, the loop will be just two lines of code anyway.

这篇关于如何在选中复选框时选择列表框中的所有项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆