Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding the Checkbox in a CheckListBox to a dataset

Status
Not open for further replies.

DaveRussell

Programmer
Jul 31, 2003
22
CA
I am trying to make a dataset mirror the users input to a CheckListBox - eg. when the user checks an option, the dataset is updated.

what is the easiest way to do that?

Thanks
Dave.
 
I should elaborate.
Basically i have 1 listbox with options, and one checkedlistbox with specifics related to the options. when a user selects an item in the listbox, the checkedlistbox changes. The CheckedListBox is bound to a DataSet, and records to the dataset when the user selected specific items in it using the following code in the "Private Sub clbSpecifics_ItemCheck":

If objDS.Tables(lbRoofingOptions.SelectedValue).Rows(clbSpecifics.SelectedIndex).Item("Selected") = True Then
objDS.Tables(lbRoofingOptions.SelectedValue).Rows(clbSpecifics.SelectedIndex).Item("Selected") = False
Else
objDS.Tables(lbRoofingOptions.SelectedValue).Rows(clbSpecifics.SelectedIndex).Item("Selected") = True
End If

now, the user is supposed to continue in the first listbox and select a different item. the problem is that i would like to allow the user to go back and change his selections in the CheckedListBox from his first ListBox selection... if that makes sense. so, in the "Private Sub lbRoofingOptions_SelectedIndexChanged" i put the following code to repopulate the CheckedListBox with the users selections, if any have been made:

'Check the appropriate boxes.
For i = 0 To objDS.Tables(lbRoofingOptions.SelectedValue).Rows.Count - 1
If objDS.Tables(lbRoofingOptions.SelectedValue).Rows(i).Item("Selected") = True Then
clbSpecifics.SetItemCheckState(i, CheckState.Checked)
Else
clbSpecifics.SetItemCheckState(i, CheckState.Unchecked)
End If
Next i

so the problem comes that when the above code runs, it triggers the item_check code (due to the "SetItemCheckState()" ) as well, which deselects the last item selected in the CheckedListBox and/or deselects the same item in the dataset.

to sum up....
I need a way to directly bind the Checkbox in a CheckListBox to a Boolean Column in a Dataset, or find a way to supress the inclination for the ListBox to trigger the CheckedListBox code.

i think that either of these would help, but i am not familiar with VB's language enough to know how to go about this. i have actually spent all day... literally at my chair. my back hurts. any help would be appreciated... by my back.

thanks again,
dave.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top