复选框中的预选项目 [英] Preselected item in checklistbox

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

问题描述

我需要帮助,我想在启动应用程序时预先选择一些项目
例如.
我有物品
1.苹果
2.牛
3.牛奶
4. breat
我何时启动应用程序我已选择
1.苹果

我尝试使用此代码但不起作用

i need help i want to preselect some items when i start the application
for exampe.
i have items
1. apple
2. cow
3. milk
4. breat
whent i start app i have selected
1. apple

i try this code but not work

'ram ales de la inceput ram1
       Dim selectedIndex1 As Integer = CheckedListBox1.SelectedIndex
       selectedIndex1 = 1
       CheckedListBox1.SetItemChecked(selectedIndex1, True)

推荐答案

事物的结合...是您首先填充选中的列表框?如果是这样,请记住您的索引是从零开始的,即:它从0到n-1,其中n是列表中的项数.

另外,您无需将selectedIndex1的值设置为CheckedListBox1.SelectedIndex,因为您将在下一行将其立即更改为1.
Couple of things... are you populating your checked listbox first? If so, remember that your index is zero based, ie: it goes from 0 to n-1 where n is the number of items in your list.

Also, there''s no need for you to set the value of selectedIndex1 to CheckedListBox1.SelectedIndex, as you are immediately changing it to 1 on the next line.


在您的代码中使用此代码表单加载事件处理程序
Use this code in your form load event handler
CheckedListBox1.SetItemChecked(0, True)


0 =苹果"
1 =母牛"
2 =牛奶"
等等....


0 = "Apple"
1 = "Cow"
2= "Milk"
etc....


将所选索引的值更改为0,因为第一个索引将为零.这样做是为了避免出现异常.


Change the value of your selected index to 0 since that the first index would be zero. Do it like this so that you wouldn''t have exceptions.


if(CheckedListBox1.Items.Count != 0)
{
   selectedIndex = 0;
   //wherein 0 is apple.
}



如果它解决了您的问题,请标记为答案/

最好的问候,
爱德华



Please mark this as answer if it solved your problem/

Best regards,
Eduard


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

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