Why are my DataGridViews inside the Tab Controls are not being affected by my code?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Why are my DataGridViews inside the Tab Controls are not being affected by my code?



I have 2 forms, the first form is for the button to trigger the code and the second form has the tabcontrol with 5 tab pages which will receive the code. Each one of the tab pages in the second form has 1 datagridview(so tab 1 contains datagridview1, tab 2 contains datagridview2 and so on. In the second form's form load, I populated each datagridviews:


Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
me.DataGridView1.Rows.Add("Apple", "Orange")
me.DataGridView2.Rows.Add("Banana", "Strawberry")
me.DataGridView3.Rows.Add("Hotdog", "Burger")
me.DataGridView4.Rows.Add("Pizza", "Monkey")
me.DataGridView5.Rows.Add("Melon", "Lemon")



Now I want to clear all rows using the button from the first form:


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Form2.DataGridView1.Rows.Clear()
Form2.DataGridView2.Rows.Clear()
Form2.DataGridView3.Rows.Clear()
Form2.DataGridView4.Rows.Clear()
Form2.DataGridView5.Rows.Clear()
Me.Hide()
Form2.show()



But it doesn't seem like it is working. Any idea why is that?
Highly appreciated





Probably an issue with default/implicit form instances. Forms are classes, so you should create instances of them and pass them as needed.
– Plutonix
13 hours ago





Where does button1 reside? You doing a Form2.Show after you clear so it's triggering the Form2_Load when is filling them back in.
– Charles May
10 hours ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results