Select checkbox from checkbox list through code.
-
HI Friends, I am trying to match the value from database with checkbox list items and if matched I want to check the checkbox: if(chklstGroups.Items[i].ToString() == objGroups.Title) { chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error chklstGroups.SelectedValue = i; // Method 2 -- No Error but no result. chklstGroups.SetSelected(i,true); // Method 3 -- No Error but no result. break; } Please help me if you know the solution. Regards,
Sushant Duggal.
-
HI Friends, I am trying to match the value from database with checkbox list items and if matched I want to check the checkbox: if(chklstGroups.Items[i].ToString() == objGroups.Title) { chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error chklstGroups.SelectedValue = i; // Method 2 -- No Error but no result. chklstGroups.SetSelected(i,true); // Method 3 -- No Error but no result. break; } Please help me if you know the solution. Regards,
Sushant Duggal.
Wouldn't it be something like:
chklstGroups.Items[i].Checked=true;
? The day has been too long, I've spent frittered too much time on here today, I need sleep. -- modified at 2:25 Thursday 3rd May, 2007 This worked for me:this.checkedListBox1.SetItemChecked(0,true) ;
-
HI Friends, I am trying to match the value from database with checkbox list items and if matched I want to check the checkbox: if(chklstGroups.Items[i].ToString() == objGroups.Title) { chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error chklstGroups.SelectedValue = i; // Method 2 -- No Error but no result. chklstGroups.SetSelected(i,true); // Method 3 -- No Error but no result. break; } Please help me if you know the solution. Regards,
Sushant Duggal.
Sushant Duggal wrote:
chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error
What sort of error? -- modified at 2:41 Thursday 3rd May, 2007 More information required.
-
HI Friends, I am trying to match the value from database with checkbox list items and if matched I want to check the checkbox: if(chklstGroups.Items[i].ToString() == objGroups.Title) { chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error chklstGroups.SelectedValue = i; // Method 2 -- No Error but no result. chklstGroups.SetSelected(i,true); // Method 3 -- No Error but no result. break; } Please help me if you know the solution. Regards,
Sushant Duggal.
Use debugger to check whether the "if" statement evaluates to true by creating breakpoint at a line inside the if block.
Regards, Arun Kumar.A
-
HI Friends, I am trying to match the value from database with checkbox list items and if matched I want to check the checkbox: if(chklstGroups.Items[i].ToString() == objGroups.Title) { chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error chklstGroups.SelectedValue = i; // Method 2 -- No Error but no result. chklstGroups.SetSelected(i,true); // Method 3 -- No Error but no result. break; } Please help me if you know the solution. Regards,
Sushant Duggal.
I no longer use
CheckedListBox
es, I useTreeView
s that look likeCheckedListBox
es; they're much more advanced. -
Sushant Duggal wrote:
chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error
What sort of error? -- modified at 2:41 Thursday 3rd May, 2007 More information required.
Object reference not set.
Sushant Duggal.
-
Object reference not set.
Sushant Duggal.
Then I suppose your
chklstGroups
hasn't been set. Show more of the code. -
HI Friends, I am trying to match the value from database with checkbox list items and if matched I want to check the checkbox: if(chklstGroups.Items[i].ToString() == objGroups.Title) { chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error chklstGroups.SelectedValue = i; // Method 2 -- No Error but no result. chklstGroups.SetSelected(i,true); // Method 3 -- No Error but no result. break; } Please help me if you know the solution. Regards,
Sushant Duggal.
try this: if( (objGroups.Title != null || objGroups.Title != DBNull) && chklstGroups.Items[i].ToString() == objGroups.Title.ToString()) { chklstGroups.SetItemChecked(i,true); // Method 1 -- Generates Error chklstGroups.SelectedValue = i; // Method 2 -- No Error but no result. chklstGroups.SetSelected(i,true); // Method 3 -- No Error but no result. break; } Hope it helps...