Why are my DataGridViews inside the Tab Controls are not being affected by my code?
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
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.
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