Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

vb.net - How to pass value from Form1 to Form2

I'm making a program that generates SQL Server code to use it in my VB.NET program.

I have this first form that contains the connection like you see in picture below:

1

The connection works 100%, but in the second form I have two DataGridViews, one for tables and one for fields.

So when I click on any table of DataGridView1 => DataGridView2 show it fields:

2

When I click on DataGridView1 to get the value of ComboBox from Form1 to use it in Form2 I have the following error:

Failed to connect to server.

Code:

Dim frm As New Form2
prd.ServerConnection = New ServerConnection(frm.ComboServer.Text) ' here the error
prd.DGVField(MetroGridTables, MetroGridField)

I use Form1 to make connection and Form2 to make operation.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This question is a bit confusing, but this is how I would pass a variable from one form to another.

Create a class /w variable.

Public Class Variables

    Public Shared Property imavariable As String
        Get
            Return m_imavariable 
        End Get
        Set(value As String)
            m_imavariable = value
        End Set
    End Property
    Private Shared m_imavariable As String

End Class

Set the variable from form 1... variables.imavariable = string Read the variable from form2.... string = variables.imavariable


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...