Click here to Skip to main content
16,017,261 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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

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.
 
Share this answer
 
Use this code in your form load event handler
VB
CheckedListBox1.SetItemChecked(0, True)

0 = "Apple"
1 = "Cow"
2= "Milk"
etc....
 
Share this answer
 
v2
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900