Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Windows Forms
  4. MDI app with Database access

MDI app with Database access

Scheduled Pinned Locked Moved Windows Forms
helpdatabasequestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gymnast
    wrote on last edited by
    #1

    I have an MDI app; This app has 2 forms Form1 and Form2 Form1 has a ComboBox, ComboBox1, which is bound programmatically to a database; Form2 has a textbox that should display the combobox selection in Form1. Essentially, what I would like working is: In the Form1 Button1_Click event, Dim f2 as New Form2 f2 = new Form2 f2.TextBox1.Text = Me.ComboBox1.SelectedItem.Text But this does not work. So I used a Shared variable to retrieve the value of the combobox selection and use that as the value for the textbox in Form2. Public Class Class2 Private Shared meetName As String Public Sub New(ByVal mName As String) meetName = mName End Sub 'Assign Combobox selection to the variable, used in the constructor 'Provide access to NameOfMeet Property Public Shared Property NameOfMeet() As String Get Return meetName End Get Set(ByVal value As String) meetName = value End Set End Property End Class In Form1 Button_Click event: Dim obj As Class2 Try 'Instantiate Form2 Dim f2 As New Form2 f2 = New Form2 obj = New Class2(Me.ComboBox1.SelectedText) ‘While I have instantiated the Class2 (obj), I have not used it anyplace. Is this right? f2.TextBox1.Text = Class2.NameOfMeet f2.Show() Catch ex As Exception MsgBox("Error: " & ex.Message) End Try End Sub With this code, I get the following display in the Textbox in Form2 (where I would like the ComboBox selection from Form1 to display) .. “System.Data.DataRowView”. Your help is appreciated. Thanks, Gymnast

    K 1 Reply Last reply
    0
    • G Gymnast

      I have an MDI app; This app has 2 forms Form1 and Form2 Form1 has a ComboBox, ComboBox1, which is bound programmatically to a database; Form2 has a textbox that should display the combobox selection in Form1. Essentially, what I would like working is: In the Form1 Button1_Click event, Dim f2 as New Form2 f2 = new Form2 f2.TextBox1.Text = Me.ComboBox1.SelectedItem.Text But this does not work. So I used a Shared variable to retrieve the value of the combobox selection and use that as the value for the textbox in Form2. Public Class Class2 Private Shared meetName As String Public Sub New(ByVal mName As String) meetName = mName End Sub 'Assign Combobox selection to the variable, used in the constructor 'Provide access to NameOfMeet Property Public Shared Property NameOfMeet() As String Get Return meetName End Get Set(ByVal value As String) meetName = value End Set End Property End Class In Form1 Button_Click event: Dim obj As Class2 Try 'Instantiate Form2 Dim f2 As New Form2 f2 = New Form2 obj = New Class2(Me.ComboBox1.SelectedText) ‘While I have instantiated the Class2 (obj), I have not used it anyplace. Is this right? f2.TextBox1.Text = Class2.NameOfMeet f2.Show() Catch ex As Exception MsgBox("Error: " & ex.Message) End Try End Sub With this code, I get the following display in the Textbox in Form2 (where I would like the ComboBox selection from Form1 to display) .. “System.Data.DataRowView”. Your help is appreciated. Thanks, Gymnast

      K Offline
      K Offline
      Kschuler
      wrote on last edited by
      #2

      It has to do with how you are loading items into your ComboBox control. You must be binding to a DataSource. You may have to set the ComboBox.DisplayMember and ComboBox.ValueMember and then reference the ComboBox.SelectedValue instead of ComboBox.SelectedItem. Perhaps researching these will point you in the right direction. Hope this helps.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups