Checking an Item In the Check List Box


May 10, 2005
Programming Experience
Hey... everybody

I am comparing the items in a checklist box to another list of items. If certain conditions are stified then I m setting then I am setting an item as checked (programmatically) in the Checklist box.

I put a breakpoint right after I check an item in the checklist box, and then I opened the properties for the checklist box in the debug window.

I saw that the property called CheckedIndices.count = 1.

I even put a breakpoint at the Itemcheck event for that particular checklistbox, and the program does go there when I programatically check an item in the checklistbox.

When the form actually loads, I do not see any checks on the form. Is there some property that I have activate for the checks to be visible ??

JobInstrumentCheckList.SetItemCheckState(0, CheckState.Checked)
Hey Man,

Here is the code:

*****FORM LOAD**************
Private Sub RepairOrderSystemForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'pull all the data from the database, the customer search should
'be taking care of this. Whenever we double click on a job
'the page load load should be given a job ID and then Grab
'Get the values for the actuator, valve, Instrument and accessories
'And populate the List boxes and the combo boxes. 
PopulateBoxes("Valve", JobValveCombo)
PopulateBoxes("Actuator", JobActuatorCombo)
PopulateBoxes("Accessory", JobAccessoryCheckList)
PopulateBoxes("Instrument", JobInstrumentCheckList)
StatusIndex = 0
Dim i As Integer
For i = 1 To (Me.TabControl1.TabPages.Count() - 1)
Me.TabControl1.TabPages(i).Enabled = False
Next i
If Not JobId.Text = "" Then
'Call the function that will do the checks for items in the database
End If
End Sub

[size=2]********Populate Boxes Function**************

[size=2][left]Public Sub PopulateBoxes(ByVal type As String, ByVal obj As Object)

Dim proc As New RepairItemProcessor
Dim aList As ArrayList
'The only reason for this TempList, is to have a 
'"Select An Item" Choice
Dim TempList As New ArrayList
Dim anitem As New RepairItem
anitem.RepairItemName = "Select an Item"
aList = proc.getRepairItemList(type)
If Not aList Is Nothing AndAlso aList.Count > 0 Then
If type = "Instrument" Or type = "Accessory" Then
obj.DisplayMember = "RepairItemName"
obj.ValueMember = "Mechanism"
obj.DataSource = aList
obj.DisplayMember = "RepairItemName"
obj.ValueMember = "Mechanism"
obj.DataSource = TempList
End If
End If
Catch ex As Exception
Throw New Exception("AccessDBError", ex)
End Try
End Sub



*********Select Chosen Function*****************



[size=2][left]Public Sub SelectChosen(ByVal JobId As String)Dim proc As New Job_xref_RepaitItemProcessor

Dim proc2 As New RepairItemProcessor
Dim ChosenOnes As ArrayList
Dim AllTheOnes As ArrayList
'Go to the database and grab the list of the repair items 
'selected. Display the selected items on the Main Form
ChosenOnes = proc.getRepairItemList(JobId)
'Dim ChosenCount As Int16 = ChosenOnes.Count
choose(ChosenOnes, JobActuatorCombo)
choose(ChosenOnes, JobValveCombo)
choose(ChosenOnes, JobInstrumentCheckList, True)
choose(ChosenOnes, JobAccessoryCheckList, True)
JobInstrumentCheckList.SetItemCheckState(0, CheckState.Checked)
JobInstrumentCheckList.SetItemCheckState(1, CheckState.Checked)
JobInstrumentCheckList.SetItemCheckState(2, CheckState.Checked)
JobInstrumentCheckList.SetItemCheckState(3, CheckState.Checked)


End Sub


*****Choose Function*******************
Public Sub choose(ByVal obj As Object, ByVal obj2 As Object, Optional ByVal IsInstrument As Boolean = False)
Dim ChosenCount As Int16 = obj.Count 
Dim AllCount As Int16 = obj2.Items.Count
For I As Integer = 0 To (ChosenCount - 1)
For J As Integer = 0 To (AllCount - 1)
If IsInstrument Then
'dealing with the checklist boxes
If obj(I).RepairItemName = obj2.Items.Item(J).RepairItemName Then
' obj2.SetItemChecked(J, True)
End If
'Dealing with the combo boxes
If obj(I).RepairItemName = obj2.Items.Item(J).RepairItemName Then
obj2.SelectedItem = obj2.Items.Item(J)
End If
End If


End Sub


hey man.... sorry about the code... if you could just tell me about the behaviour of the check list boxes. why would the state go to unchecked after being checked??

When the item does "uncheck", should the item check event be raised??

Hey I think I have the problem identified.
In my application, I have a parent form and a child form. The parent form loads before the child form, and the checklist box is in the child form.

I tried to activate "Child Form" individually, therefore it opened as a seperate window, but the checklist WORKED. I can see the checked item in the new window. For some reason the values of the checklist box is not being passed along if I have the "frm.mdiparent" property set. Is there a way to pass all the properties when I am creating an MDI child.

Finally the problem is solved. Apparently there is bug in .NET with the Tab Control. Therefore I used the code :

"Tabpage.BindingContext = Me.BindingContext"
This alsoprovides the funtionality to remember the checked items when we are jumping between tabs on a page.

This caused a lot of problems since yesterday. Feels good to finally have it working.