如何在运行时更改选中列表框的选择模式? [英] how to change selection mode of a checked list box in runtime?
问题描述
我有一个包含单选按钮的表单
(按钮1 ---->已发布)和
(按钮2 ----> NON_ISSUED
而且我有一个选中的列表框,其中将包含某些项目.
我需要使用户能够仅在选中单选按钮1的情况下才检查复选框列表中的多个项目.
否则,如果选中单选按钮2,我想将选择模式限制为单"选择模式.
有可能吗?
在此先感谢那些有兴趣提供帮助的人:)
i have a form containing radio buttons
(button 1----> ISSUED) and
(button 2----> NON_ISSUED
and i have a checked list box which will contain certain items.
i need to enable the user to check multiple items in checked list box only if radio button 1 is checked.
else if radiobutton2 is checked i want to restrict selection mode to SINGLE selection mode.
is it possible??
thanks in advance to those who are interested to help :)
推荐答案
为什么没有两套列表控件,一个用于1的复选框列表和一个用于2的单选按钮列表.如果选择了按钮1,则隐藏单选按钮列表并显示复选框列表,否则反之.
OK,所以2个控件将不起作用.然后尝试这个.让我知道它是否对您有用.
Why not have 2 sets of list controls, a checkbox list for 1 and a radio button list for 2. If button 1 is selected, hide the radio button list and show checkbox list, else, the other way around.
OK, so 2 controls will not work. Try this then. Let me know if it works for you.
private void checkedListBox1_SelectedValueChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
checkedListBox1.SetItemCheckState(i, CheckState.Unchecked);
}
checkedListBox1.SetItemCheckState(checkedListBox1.SelectedIndex, CheckState.Checked);
}
}
[/Edit]
[/Edit]
很遗憾,对于CheckedListBox对象,不支持多选.您可以将模式设置为一项或一项.
阅读此链接以获取更多信息.
http://social.msdn.microsoft.com /Forums/zh-CN/vbbugsubmissionpilot/thread/1a4acbfe-8e1b-42a3-ac27-1ed280d8a9af/ [
Unfortunately, for CheckedListBox objects, multiple selection is not supported. You can set the mode to one item or no items.
Read this link for more info.
http://social.msdn.microsoft.com/Forums/en-US/vbbugsubmissionpilot/thread/1a4acbfe-8e1b-42a3-ac27-1ed280d8a9af/[^]
清单框不支持多选.但是将CheckOnClick =一次单选按钮切换为true以及将第二次单选按钮单击切换为false可能会有所帮助.
Multiple selection is not supported in checkedlistbox. But toggling CheckOnClick = true on one radio button click and false on second radio button click could help.
if (RadioButton1.Checked)
checkedListBox1.CheckOnClick =true;
else
checkedListBox1.CheckOnClick = false;
这不是您想要的解决方案,但可以使您的多重选择更加容易.
It''s not the solution you want, but could make your multiple selection easier.
这篇关于如何在运行时更改选中列表框的选择模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!