Okay, so I'm what they call a newbie like others were when they just started coding.
I love working with listboxes and TreeView, so as I make a breakthrough with something I didnt understand, I'll try and share. Hopefully I'll put together an actual sample when i learn how to deploy.
the following code solves the following problems:
1. Adding the Tag of a tree node when its checkbox is selected to a listbox
2. Removing the Tag of a tree node when its checkbox is de-selected from a listbox
3. Preventing Duplicate values in a listbox.
Hope this helps someone ;-) NB: I claim no ownership or brilliance for codes, I just read, copy, paste, edit. Thanks to all the Geniuses out there that help a normal guy like me to survive by sharing what you know.
I love working with listboxes and TreeView, so as I make a breakthrough with something I didnt understand, I'll try and share. Hopefully I'll put together an actual sample when i learn how to deploy.
the following code solves the following problems:
1. Adding the Tag of a tree node when its checkbox is selected to a listbox
2. Removing the Tag of a tree node when its checkbox is de-selected from a listbox
3. Preventing Duplicate values in a listbox.
VB.NET:
Dim s As String = e.Node.Text() & " " & e.Node.Tag()
Dim IsExists As Boolean
Try
If e.Node.Checked.Equals(True) Then
For i As Integer = 0 To ListBox1.Items.Count - 1 ' THE FOR BLOCK IS A CHECK TO PREVENT DUPLICATES IN THE LISTBOX
If ListBox1.Items(i) = s Then 'sItem: is item you get from your text file
IsExists = True 'IsExists: is boolean
Exit For
Else
IsExists = False
End If
Next
If IsExists = False Then
ListBox1.Items.Add(s)
End If
Else : e.Node.Checked.Equals(False)
For i As Integer = 0 To ListBox1.Items.Count - 1 ' THIS FOR BLOCK IS To REMOVE ITEMS PREVIOUSLY SELECTED FROM THE LISTBOX
If ListBox1.Items(i) = s Then 'sItem: is item you get from your text file
IsExists = True 'IsExists: is boolean
Exit For
Else
IsExists = False
End If
Next
If IsExists = True Then
ListBox1.Items.Remove(s)
End If
End If
Catch ex As Exception
End Try
End Sub
Hope this helps someone ;-) NB: I claim no ownership or brilliance for codes, I just read, copy, paste, edit. Thanks to all the Geniuses out there that help a normal guy like me to survive by sharing what you know.
Last edited by a moderator: