I have a VB.net Windows form that contains a checklistbox. I need to check or uncheck each item based on boolean values I have stored in an xml file. I also need to update that xml file when each item's checkbox is changed. My VB is competent, but nowhere near an expert level, so I'm not sure how to do this using a checklistbox. My alternative is to just use checkboxes themselves inside a panel, but a checklistbox keeps things together nicer. If anyone can help me out how to do this, I'd appreciate it. Below is pseudo-code of what I have and need to do.

Public Property Use_One() As Boolean
Public Property Use_Two() As Boolean
Public Property Use_Three() As Boolean
Public Property Use_Four() As Boolean
Public Property Use_Five() As Boolean

Private Sub frmData_Load() Handles frmData.Load
  Me.clbData.Items.Add("One", False)
  Me.clbData.Items.Add("Two", False)
  Me.clbData.Items.Add("Three", False)
  Me.clbData.Items.Add("Four", False)
  Me.clbData.Items.Add("Five", False)

  One.Checked = Use_One
  Two.Checked = Use_Two
  Three.Checked = Use_Three
  Four.Checked = Use_Four
  Five.Checked = Use_Five
End Sub

Private Sub chkOne_CheckedChanged() Handles chkOne.CheckedChanged
  Use_One = One.Checked
End Sub

Private Sub chkTwo_CheckedChanged() Handles chkTwo.CheckedChanged
  Use_Two = Two.Checked
End Sub

Private Sub chkThree_CheckedChanged() Handles chkThree.CheckedChanged
  Use_Three = Three.Checked
End Sub

Private Sub chkFour_CheckedChanged() Handles chkFour.CheckedChanged
  Use_Four = Four.Checked
End Sub

Private Sub chkFive_CheckedChanged() Handles chkFive.CheckedChanged
  Use_Five = Five.Checked
End Sub

Your pseudo code seem ok, but I would suggest you look at using the controls collection and event handlers to handle the changes, msdn has some good articles on that. This will simplify your code greatly and maybe expand your expertise :)

This article has been dead for over six months. Start a new discussion instead.