|
-
Mar 26th, 2019, 05:09 PM
#1
Thread Starter
Member
Refresh a combobox in a parent tabpage after making an entry in child tabpage
Hello,
I am using MySQL Database which is connected to Visual Studio Community 2017 Community Edition software. I have used a TabControl form, with tables in each TabPage. I am trying to refresh a combobox on the parent TabPage, after making a data entry in a textbox in the child TabPage. The child form has two textboxes: "txtBookID" and "txtBookName". The textbook "txtBookID" is autoincremented. The Parent form has a combobox called "CboBookID_fkey". If I make a new entry in the textbook "txtBookName", I would like the CboBookID_fkey, to update with the new SelectedItem. However, when I make an update in the textbox on the child TabPage, the "CboBookID_fkey" combobox do not automatically update with the changes. My vb.net code is shown below: -
Code:
Imports MySql
Imports MySql.Data.MySqlClient
Imports System.Configuration
Imports MySql.Data
Public Class Form1
Inherits Form
Dim conString As String = "Server=localhost;Port=3306;Database=mydatabase;userid=root;password=password;persist security info=True"
Dim con As MySqlConnection = New MySqlConnection(conString)
Private Sub SelectBookName(cb As ComboBox)
Dim con As New MySqlConnection(conString)
Dim myCommand As MySqlCommand = connection.CreateCommand()
myCommand.CommandText = "SELECT BookName from Books"
con.Open()
Dim reader As MySqlDataReader
reader = myCommand.ExecuteReader()
While reader.Read()
cb.Items.Add(reader.GetString("BookName"))
End While
con.Close()
End Sub
Private Sub TabPage2_Click(sender As Object, e As EventArgs) Handles TabPage2.Click
InitializeComponent()
CboBookID_fkey.Items.Clear()
SelectBookName(CboBookID_fkey)
End Sub
End Class
Last edited by wire_jp; Mar 26th, 2019 at 07:49 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|