hi guys,
i have a main form and what i want to do is to display the informations on another form (in listview) which has the input values on the main form. when i create a second form i cant access any of the controls on the main form. How to have access to controls which are on a different windows form ???

Dani AI

Generated

Short summary and recommended approach.

As described, the goal is to show values entered on a main form inside a ListView on a second form. pointed out that direct access to another form's controls can work and posted a link with more detail. Those quick options work for tiny prototypes, but they couple the forms tightly and make maintenance harder. Prefer passing data (values or typed objects), not passing or reaching into UI controls on another form.

Two simple, safer patterns (VB.NET):

' Constructor injection: pass the data when creating the second form
Dim values = New List(Of String) From {TextBoxA.Text, TextBoxB.Text}
Dim f As New DetailForm(values)
f.ShowDialog()
' Property setter: set values before showing the form
Dim f As New DetailForm()
f.Items = values
f.Show()

Inside the receiving form, populate the ListView from the passed collection. Keep controls Private in the designer and expose only the properties or methods you need; avoid flipping Modifiers to Public as a first fix.

Practical tips and pitfalls

  • If you need a reply from the child form (e.g., edited data), use ShowDialog and read a public property after it closes, or use an event/delegate for asynchronous callbacks.
  • If a compile error says a control is inaccessible, the designer defaults to Private; expose a property instead of changing the control modifier.
  • Beware VB.NET default form instances (Form1 vs New Form1()); make sure you are setting values on the same instance you will show.
  • For background threads, marshal UI updates with Invoke/BeginInvoke; do not update ListView from a worker thread.

Using these patterns keeps the UI code clearer, easier to test, and less error-prone than directly manipulating another form's controls.

Recommended Answers

All 3 Replies

Here is a very good article.

you should use the name of the forms for example

form1.textbox1.text="testing"

Thank you very much meffe. This was all that i want to know :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.