I have two forms, form1 and form2. In form1 i have a textbox & a button which onclick opens form2. in form2 i have a listbox.when a user selects a value from listbox in form2(manually inserted few items in designer) , this corresponding value gets populated on textbox in form1. This works fine and below is my code.
Form1: Public FR As frmNCNtest = Nothing <STAThread()> _ Private Shared Sub main() Application.Run(New frmNCNpopup) End Sub Private Sub btn_openchild_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_openchild.Click FR = New frmNCNtest FR.ShowDialog(Me) End Sub Private Sub frmNCNpopup_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated If Not FR Is Nothing Then txt_test3.Text = FR.ListBox1.SelectedItem.ToString() FR.Dispose() End If End Sub
Form2: Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged Me.Close() End SubNow how to insert items at runtime from database in listbox on form 2. I tried following code, but it only inserts forst item ,even that not in listbox on form2 but on textbox in form1. below is code:
Form2: Private Sub abc() Try If ConState = False Then Connect() End If strSQLtest = SqlQry.qryNCNreason Dim cmd1 As New OleDbCommand(strSQLtest, dbConn) Dim datareader As OleDbDataReader = cmd1.ExecuteReader() Dim list As New ArrayList If datareader.HasRows Then While datareader.Read() list.Add(datareader.GetString(0)) End While End If Me.ListBox1.DataSource = list Catch ex As OleDbException MessageBox.Show(ex.Message, "Database read error!", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End SubCan anyone pls help me how to insert values in listbox from database table and whats wrong here. Thanks.


Sign In
Create Account

Back to top









