Combo Boxes (VB)

MarkItZero

Active member
Joined
Apr 10, 2003
Messages
43
Location
under the desk in my office
Combo Boxes

Hello,
I have two combo boxes on a form. One combo box contains UserNames, the second combo box contains the JobNames that have been assigned to each User. When the form loads, the first UserName is displayed in CmboUserName and the first JobName for that User is displayed in CmboJobNames. However, I cant seem to get CmboJobNames to properly refresh when a different UserName is selected. Here is the code I have now...

Code:
Fill CmboUserName
        Fill DSUsers1 Dataset
        OleDbDataAdapter2.Fill(DsViewOthersUserName1, "Users")

        Create Dataview
        Dim dm As DataTable = DsViewOthersUserName1.Tables("Users")
        Dim DVCmboUserName As DataView = New DataView(dm)
        DVCmboUserName.RowFilter = "UserName <> " & CurrentUser & ""

        Populate Combo Box
        CmboUserName.DataSource = DVCmboUserName
        CmboUserName.DisplayMember = "UserName"

        Fill CmboJobName
        FillCmboJobName(CmboUserName.Text)
End Sub

CmboUserName Index Change
    Private Sub CmboUserName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmboUserName.SelectedIndexChanged
        Refresh CmboJobName
        FillCmboJobName(CmboUserName.Text)
    End Sub

Sub FillCmboJobName(ByVal UserName As String)

        Fill CmboJobName
        Fill DSUsers1 Dataset
        OleDbDataAdapter1.Fill(DsViewOthersJobName1, "EstHeader")

        Create Dataview
        Dim dm2 As DataTable = DsViewOthersJobName1.Tables("EstHeader")
        Dim DVCmboJobName As DataView = New DataView(dm2)
        DVCmboJobName.RowFilter = "UserName = " & UserName & ""

        Populate Combo Box
        CmboJobName.DataSource = DVCmboJobName
        CmboJobName.DisplayMember = "Job"

    End Sub


Any Suggestions?
Thanks!
 
Last edited by a moderator:
Well it works now.

No thanks to any of you :p

I didnt even change any the code, I dont know what the problem was.

Now I am trying to figure out how to display an empty CmboJobName if the CmboUserName selected has no jobs attached.

Any suggestions on that?
Thanks
 
Originally posted by Robby
How motivating is this?

I am trying to motivate you by pointing out the lack of expertise on this board, since no one was able to answer my seemingly simple question. Its a challenge. And a joke.

(I dont mean to offend the people I am asking for help, if you took it that way I apologize, perhaps my attempt at light humor was poorly worded)
 
When the UserName Combo is selected how many Jobs may show up in the Jobs Combo? Will it be many or just one?
 
Well it works now.
I didnt even change any the code, I dont know what the problem was.

Given your quote, my first response (none), was perfect - apparently no help was required :)

-Nerseus
 
Originally posted by Robby
When the UserName Combo is selected how many Jobs may show up in the Jobs Combo? Will it be many or just one?

It could be many, it could be none, it could be just one.

I was able to fix this problem as well, by adding a If..Then..Else statement before filling the JobName Combo Box.

Code:
Fill CmboJobName Method
    Sub FillCmboJobName(ByVal UserName As String)

        Fill DSUsers1 Dataset
        OleDbDataAdapter1.Fill(DsViewOthersJobName1, "EstHeader")

        Create Dataview
        Dim dm2 As DataTable = DsViewOthersJobName1.Tables("EstHeader")
        Dim DVCmboJobName As DataView = New DataView(dm2)
        DVCmboJobName.RowFilter = "UserName = " & UserName & ""

        If DVCmboJobName.Count > 0 Then
            Populate Combo Box
            CmboJobName.Show()
            CmboJobName.DataSource = DVCmboJobName
            CmboJobName.DisplayMember = "Job"
        Else
            CmboJobName.DataSource = Nothing
            CmboJobName.Hide()
        End If

    End Sub

it may not be pretty, but it works.
Thanks
 
Back
Top