Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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...

 

'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!

Edited by Banjo
Posted

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

Posted
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)

  • *Experts*
Posted

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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted
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.

 

'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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...