2 Replies - 3705 Views - Last Post: 08 December 2010 - 03:08 AM Rate Topic: -----

#1 DieselUofA   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 10-November 09

How to Populate a ComboBox using an Array in a 3 Tier Structure

Posted 08 December 2010 - 12:09 AM

I have referenced these forums many times and would now like to be one of the helped coders on here. It's a simple 3-Tier Structure Windows Form Application using Visual Basics 2008 express edition. I need to populate a ComboBox (User Interface Layer) using an Array with only 3 names (Data Access Layer and Business Logic Layer). I think I'm close to it but I'm unable to pass the data from the DAL all the way to the UI properly. When I run the application, My ComboBox gives me choices but the three choices are "False", "False", and "False"
Help would be, obviously, Greatly Appreciated!

I sincerely Thank You in advance.

- USER INTERFACE LAYER -
Public Class Names_UI

    Private Name1 As String
    Private Name2 As String
    Private Name3 As String

    Private Sub NamesComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NamesComboBox.SelectedIndexChanged

        'I've tried put the code below, Here.

    End Sub


    Private Sub Names_UI_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim TheNames As New Names_BL()
        TheNames.LoadNames()

        NamesComboBox.Items.Add(TheNames.GetName1)
        NamesComboBox.Items.Add(TheNames.GetName2)
        NamesComboBox.Items.Add(TheNames.GetName3)

    End Sub
End Class




- BUSINESS LOGIC LAYER -
Public Class Names_BL

    Private Name1 As String
    Private Name2 As String
    Private Name3 As String

    Public Function GetName1() As String
        Return Name1
    End Function

    Public Sub SetName1(ByVal NewName1 As String)
        Name1 = NewName1
    End Sub

    Public Function GetName2() As String
        Return Name2
    End Function

    Public Sub SetName2(ByVal NewName2 As String)
        Name2 = NewName2
    End Sub

    Public Function GetName3() As String
        Return Name3
    End Function

    Public Sub SetName3(ByVal NewName3 As String)
        Name3 = NewName3
    End Sub

    'array being refrenced
    Public Sub LoadNames()
        Dim NamesDA As New Names_DA()
        NamesDA.LoadNamesDA()

        Name1 = NamesDA.GetName1
        Name2 = NamesDA.GetName2
        Name3 = NamesDA.GetName3
    End Sub

End Class




- DATA ACCESS LAYER CODE-
Public Class Names_DA

    Private Name1 As String
    Private Name2 As String
    Private Name3 As String

    Public Function GetName1() As String
        Return Name1
    End Function

    Public Sub SetName1(ByVal NewName1 As String)
        Name1 = NewName1
    End Sub

    Public Function GetName2() As String
        Return Name2
    End Function

    Public Sub SetName2(ByVal NewName2 As String)
        Name2 = NewName2
    End Sub

    Public Function GetName3() As String
        Return Name3
    End Function

    Public Sub SetName3(ByVal NewName3 As String)
        Name3 = NewName3
    End Sub

    Public Sub LoadNamesDA()

        'Declares array
        Dim Names(0 To 2) As String

        Name1 = Names(0) = "John"
        Name2 = Names(1) = "Jeremy"
        Name3 = Names(2) = "Chris"

    End Sub

End Class




Is This A Good Question/Topic? 0
  • +

Replies To: How to Populate a ComboBox using an Array in a 3 Tier Structure

#2 DieselUofA   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 10-November 09

Re: How to Populate a ComboBox using an Array in a 3 Tier Structure

Posted 08 December 2010 - 02:17 AM

Is there an easier way to do this or is something just misplaced?
Was This Post Helpful? 0
  • +
  • -

#3 DieselUofA   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 10-November 09

Re: How to Populate a ComboBox using an Array in a 3 Tier Structure

Posted 08 December 2010 - 03:08 AM

I finally figured it out!

Instead of this on the DAL:
    Public Sub LoadNamesDA()

        'Declares array
        Dim Names(0 To 2) As String

        Name1 = Names(0) = "John"
        Name2 = Names(1) = "Jeremy"
        Name3 = Names(2) = "Chris"

    End Sub


---- I simply moved Name1, Name2, and Name3 down to their own lines ----
    Public Sub LoadNamesDA()

        'Declares array
        Dim Names(0 To 2) As String

        Names(0) = "John"
        Names(1) = "Jeremy"
        Names(2) = "Chris"

        Name1 = Names(0)
        Name2 = Names(1)
        Name3 = Names(2)

    End Sub


I knew it was something simple. Thanks Anyways
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1