Hello,
I'm new to VB and OOP and I'm jammed on something. I need to refer to checkboxes on a form by their names.
Form1 contains a DataGridView of 15 columns. I also have a context menu with 15 items that the user can check/uncheck to make the column visible/hidden. To do this I set the AccessibleName property of each ToolStripMenuItem to the name of the corresponding column in the DataGridView. Here's the code that handles it.
Private Sub ContextMenuStrip1_ItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles ContextMenuStrip1.ItemClicked
Dim item As ToolStripMenuItem
item = e.ClickedItem
If item.Checked = False Then
DataGridView.Columns(item.AccessibleName).Visible = True
item.Checked = True
Else
item.Checked = False
DataGridView.Columns(item.AccessibleName).Visible = False
End If
End Sub
I also want the user to have a friendlier way of choosing the columns to display so I created Form2 with 15 checkboxes. When the form loads I need to set all those checkboxes to the value of their corresponding ToolStripMenuItem and on exit I need to set my 15 ToolStripMenuItems and my 15 DataGridView columns.
I don't like the idea of manually coding 45 statements when I'm sure there is a better of doing this. Can I iterate through either the ToolStripMenuItems or the DataGridView columns and use their names or accessiblename properties to retrieve the value of the corresponding checkbox
I really hope I'm explaining myself well :)

Refer to object by name.
Duncan-Countrywide
DavidBoyCA21
Hi Eric,
Every Formobject you drag in the designer is at runtime a control.
Alle the Controls hang together like a tree:
For example: you have one panel(p) in your form(f), f.Controls(0) might then be panel(p);
If you put other Formobjects to the panel(p) i.e. a Checkbox(c), you can access the control like: f.Controls(the control index of p).Controls(the control index of c).
That means, give me the Controls of f, search there the control p, and then go to control c.
If you go deeper in this area of programming, you are one further step away of static programming, but believe me it's not always that easy. Begin your work with the controls of your panel.
Best regards
Lucas