MarkItZero Posted April 10, 2003 Posted April 10, 2003 (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 April 10, 2003 by Banjo Quote
MarkItZero Posted April 11, 2003 Author Posted April 11, 2003 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 Quote
Moderators Robby Posted April 11, 2003 Moderators Posted April 11, 2003 No thanks to any of you :p How motivating is this? Quote Visit...Bassic Software
MarkItZero Posted April 11, 2003 Author Posted April 11, 2003 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) Quote
Moderators Robby Posted April 11, 2003 Moderators Posted April 11, 2003 When the UserName Combo is selected how many Jobs may show up in the Jobs Combo? Will it be many or just one? Quote Visit...Bassic Software
*Experts* Nerseus Posted April 11, 2003 *Experts* Posted April 11, 2003 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 Quote "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
MarkItZero Posted April 14, 2003 Author Posted April 14, 2003 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.