YongJ
YongJ

Reputation: 47

How to refresh form after selecting value from combobox

I would like to know if it is possible to refresh the current windows form I am at after selecting another value from the combo box in order to display the details of that item onto several other textboxes?

So my table looks like table name : program program_id program_name program_desc 1 T1 desc1

This is the code i am using atm

Dim connection As New SqlClient.SqlConnection
    connection.ConnectionString = "pathway"
    Dim dr As SqlDataReader
    Dim prognamedesc As String
    Dim filetypetxt As String

    Dim prognamecombo As String
    Dim filetypecombo1 As String
    Dim command As New SqlCommand
    Dim querycommand As New SqlCommand
    connection.Open()
    'THIS SECTION LOADS DATA FROM THE TABLES'
    Try

        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "select program_name,filetype from program order by program_name; select * from filetype"
        querycommand.Connection = connection
        querycommand.CommandType = CommandType.Text
        querycommand.CommandText = "select program_name,program_desc , filetype from program where program_name like" & FiletypeComboBox1.SelectedItem & ""

        dr = command.ExecuteReader

        While dr.Read()

            prognamecombo = dr(0)
            Program_nameComboBox.Items.Add(prognamecombo)

        End While

        dr.NextResult()
        While dr.Read()
            filetypecombo1 = dr(0)
            FiletypeComboBox1.Items.Add(filetypecombo1)
            FiletypeComboBox1.SelectedItem = filetypecombo1
        End While
        dr.NextResult()
        While dr.Read()
            filetypetxt = dr(0)
            FiletypeLabel1.Text = filetypetxt

        End While
        dr.NextResult()
        While dr.Read()
            prognamedesc = dr(0)
            Program_descTextBox.Text = prognamedesc
        End While

    Catch ex As Exception
        MsgBox(ex.Message)
    End Try





    connection.Close()

I was wondering if this is doable using the current code?

Upvotes: 0

Views: 1434

Answers (1)

Rami M. Nassar
Rami M. Nassar

Reputation: 102

To implement this you have to do two things, First put all your code inside a method and call it something like RefreshForm()

public void RefreshForm()
{
  // your code and binding goes here
}

The second step is by using selected index changed event over combobox you just call the method that includes all your binding code.

Upvotes: 1

Related Questions