|
Answer» I have a programming background, but I am new to vb.net. I am working on my first real vb.net project and I have a listview on the main form (Form1). I have a button the user can click on to open a new form that I want to have the listview from Form1. The new form has some fields to add values to the listview, and when the user clicks on OK in the new form, I want the new information to show back up in the listview on the original form.
So I am thinking I need to pass a pointer to the address of the listview to the new form ... or something like that?
I have the listview and adding values part working in the new form, but I can't figure out how to get the new form to start off with the Form1 values, and then how to get the updated values back to Form1.This used to be so simple in VB6. One method is to create a module where you can create a public instance of each form.
Module: Code: [Select]Module Module1 Public FForm1 As New Form1 Public FForm2 As New Form2
Sub Main() FForm1.ShowDialog() End Sub End Module
Once that's out of the way, you can reference the controls on either form:
Form 1 Code: [Select]Public CLASS Form1 INHERITS System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click FForm2.Show() End Sub End Class
Form 2 Code: [Select]Public Class Form2 Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim lvi As New ListViewItem(FForm2.TextBox1.Text)
FForm1.ListView1.Items.Add(lvi) FForm2.Hide() End Sub End Class
The last thing is to untick the enable application framework box in the application properties screen and POINT the startup object to the module name.
Hope this helps Thanks, Sidewinder! I will TRY it shortly and let you know how it goes.I think you should refer to computer experts so that you can have GREAT comments!!-
|