我如何显示使用vb.net加载第一个表单时显示的第一个面板

时间:2019-03-04 03:37:52

标签: mysql vb.net visual-studio

这是main的代码:

Imports MySql.Data.MySqlClient
Public Class main
    Dim cn As New MySqlConnection
    Dim COMMAND As MySqlCommand

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        FilterData("")
    End Sub
    Private Sub main(sender As Object, e As EventArgs) Handles MyBase.Load
        FilterData("")
    End Sub

    Private Sub Form_Resize()
        Static IsAlreadyResized As Boolean
        If Not IsAlreadyResized Then
            Me.WindowState = vbMaximizedFocus
            IsAlreadyResized = True
        End If
    End Sub



    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        add.Dispose()
        switchpanel(search)
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        search.Dispose()
        switchpanel(add)
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

        switchpanel(del)
    End Sub

    Sub switchpanel(ByVal panel As Form)
        Panel1.Controls.Clear()
        panel.TopLevel = False
        Panel1.Controls.Add(panel)
        panel.Show()
    End Sub

    Public Sub FilterData(valueToSearch As String)
        cn.ConnectionString = "server=localhost; userid=root; password=4102123; database=pis"
        Dim SearchQuery As String = "select * from pis.patient_info where concat(patient_id,Name,Birth_Date,Birth_Place,Address,Nationality,Religion,Civil_Status,Age,Occupation,Gender,Blood_Type,Medical_History) like '%" & valueToSearch & "%'"
        Dim command As New MySqlCommand(SearchQuery, cn)
        Dim adapter As New MySqlDataAdapter(command)
        Dim table As New DataTable()
        DataGridView1.Hide()

        adapter.Fill(table)
        DataGridView1.DataSource = table

    End Sub

    Private Sub TextBox1_Click(sender As Object, e As EventArgs) Handles TextBox1.Click
        search.Close()
        add.Close()
        Application.Restart()
        Me.Height = 900
        FilterData(TextBox1.Text)
        DataGridView1.Show()
    End Sub

    Private Sub TextBox1_MouseLeave(sender As Object, e As EventArgs) Handles TextBox1.MouseLeave
        FilterData(TextBox1.Text)
        DataGridView1.Hide()
    End Sub

    Public Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

        FilterData(TextBox1.Text)
        DataGridView1.Show()
    End Sub

End Class

这是必须从主代码返回的代码,或者仅显示 当我在文本框中键入内容时,datagridview1可以工作,当我使用代码Application.Restart()并且在切换到其他面板之前可以使用,但是当我以其他形式切换面板并再次搜索时,它不显示,我想显示datagridview1就像我启动程序时一样,不重新启动它Application.Restart()

Private Sub TextBox1_Click(sender As Object, e As EventArgs) Handles TextBox1.Click
        search.Close()
        add.Close()
        Application.Restart()
        Me.Height = 900
        FilterData(TextBox1.Text)
        DataGridView1.Show()
    End Sub

1 个答案:

答案 0 :(得分:0)

我将创建另一个包含 str(dataset_name)

然后调用该子程序,而不是重新启动应用程序。只要确保每次调用此子项后,您都再次为datagridview设置数据源即可。略过代码,我相信您的FilterData方法已经涵盖了这一点,但我想我会提到它。