I have a string string1="11001";
I want to Check a checkListBox in each index step according to the "1" value of
the string1
to do that I shift the string1 five times to the right and compare
the excess value with "1" ,and if the value equals then I check
the ChecklistBox index accordingly
But I think this way is not fast because i have to iterate five times
is there a better way than this ?
Please give me the idea
thx
denny
Loading
Kirtan PatelPosted Jan 15, 2010, 11:37 PM
if my answer help you than please check "Do you like this answer" check box :)
string string1 = "1101";
IEnumerator enum1 = string1.GetEnumerator();
int i=0;
while (enum1.MoveNext())
{
checkedListBox1.SetItemCheckState(i++, (CheckState)int.Parse(enum1.Current.ToString()));
}
Sam HobbsPosted Jan 17, 2010, 11:54 AM
theLizardPosted Jan 16, 2010, 4:06 PM
string s = "110101";
for(int i = 0; i < checkedListBox1.Items.Count; i++)
checkedListBox1.SetItemCheckState(i, s[i] == '1' ? CheckState.Checked : CheckState.Unchecked);
A simpler way...
The first way is not always the best way.
Sam HobbsPosted Jan 16, 2010, 11:10 AM
Sam HobbsPosted Jan 15, 2010, 10:56 PM