I am trying to generate a new checkbox in a different form.

Public Class frmAdd

    Public Sub btnitemadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnitemadd.Click

        Dim chklowerleft As New CheckBox
        Dim chkhandleft As New CheckBox
        Dim indexcounter As Integer = 4

        If chkleftlowerarm.Checked = True Then

            frmMain.chklistLA.Items.Add(chklowerleft, False)
            frmMain.chklistLA.Items.Item(2) = ("Lower Arm Actuator")

        End If

        If chkhand.Checked = True Then

            frmMain.chklistLA.Items.Add(chklowerleft, False)
            frmMain.chklistLA.Items.Item(2) = ("Lower Arm Actuator")
            frmMain.chklistLA.Items.Add(chkhandleft, False)
            frmMain.chklistLA.Items.Item(3) = ("Hand Actuator")

        End If

        Me.Close()

    End Sub

End Class

While this is great for things like those added, it may make things a bit difficult removing items down the road. Is there an easier way to name things generated?

Edited 6 Years Ago by __avd: Added [code] tags.

will you explain a little more on this.

this is for a game, and the "hand actuator" and "lower arm actuator" are in set places. however, other things such as weapons can be in variable places. also, the program will allow for modifications of such things, meaning I need to be able to add/delete things fairly often. so I can use specific indices for the two things listed, but if I wanted to put a weapon in that takes more than one index, I am hoping I dont need to use indices to name it.

frmMain.chklistLA is that a checked listbox?

frmMain.chklistLA is that a checked listbox?

yes, chklistLA is a checked listbox

the "chk" ones are checkboxes

You could just add items instead of checkboxes

chklstLa.items.add("Lower Arm Actuator",false)


You could then find them by

chklstLa.items.findstring("Lower Arm Actuator")


You could then remove them by

chklstLa.items.removeat(chklstLa.items.findstring("Lower Arm Actuator"))

You should first check

if chklstLa.findstring("Lower Arm Actuator") > -1 then
chklstLa.items.removeat(chklstLa.items.findstring("Lower Arm Actuator"))
end if

if you wanted to find the item within the checked items

If chklstLa.CheckedItems.Item(chklstLa.FindString("Lower Arm Actuator")) IsNot Nothing Then
                MsgBox("Its checked")
            End If

will try that, but unfortunately the form I am loading the checkboxes into requires that they be checkboxes. The proggy is for the quick repair of vehicles after a battle, and I need to select what to repair, what to replace, etc in the main form

Look at what i just posted. the items added to a checked list box are basically check boxes. Search them in the checked items property

Another thing.

Look into the listView control

you can have checked items as well as an icon.

You get some better functionality too.

You can name the listview item as Lower actuator and then find it by if listview1.items.contains("Lower Actuator") then do something.

I think once you use and understand the listview control you won't use the checked list box control.

Didn't think the last post posted. This post is worthless

Edited 6 Years Ago by Unhnd_Exception: n/a

This question has already been answered. Start a new discussion instead.