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 PatelRank #292 · 8.6K reputationPosted Jan 15, 2010, 6:37 PM EST
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 HobbsRank #107 · 20.5K reputationPosted Jan 15, 2010, 5:56 PM EST
Sam HobbsRank #107 · 20.5K reputationPosted Jan 16, 2010, 6:10 AM EST
theLizardRank #1,079 · 1.8K reputationPosted Jan 16, 2010, 11:06 AM EST
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 HobbsRank #107 · 20.5K reputationPosted Jan 17, 2010, 6:54 AM EST