|
-
Feb 15th, 2011, 01:14 PM
#1
Thread Starter
Member
[RESOLVED] Combobox Refuses to Populate
Hi all 
Ok, I've been working on this code for several days now, and it's making me nuts. In this windows forms app, I have a form with six comboboxes. Two are parents, one with a single child and the other with three children.
All of these work beautifully except for one of the children. The code for each one is identical, and I've verified the query against the database a dozen times. I even have another of the children that is in the very same block of code. One works beautifully, the other one refuses to populate any data. Below is the code for the one that doesn't work.
I would tell you on what line the error occurs, but it doesn't throw any errors. Try catches show nothing, and I have VS 2010 set to throw all errors, but I get nothing, just an empty combo box where there should be a list of names. Any help would be greatly appreciated.
Code:
Public Class errorTracking_submit
Dim ConnectionString = "Data Source=dvmx6030\MS2005_DEV1, 2755; user id =CRCUser;password=TWC5uck5;database=CRCTools;Connection Timeout=5"
Dim connection As SqlConnection = New SqlConnection(ConnectionString)
Dim UserID As String = Form1.adid
'Set up binding sources
Dim BindingSourceCP As New BindingSource
Dim BindingSourceDiv As New BindingSource
Dim BindingSourceEType As New BindingSource
Dim BindingSourceECat As New BindingSource
Dim BindingSourceProv As New BindingSource
Dim BindingSource_Prov As New BindingSource
Dim BindingSourceCRR As New BindingSource
Dim BindingSource_CRR As New BindingSource
Sub start() Handles MyBase.Load
Me.cb_CRR.Visible = False
Me.cb_Prov.Visible = False
Me.Prov_Label.Visible = False
Me.CRR_Label.Visible = False
Call PopComboBoxes()
End Sub
Private Sub PopComboBoxes()
'Get the data. Each DataSet must contain a Parent table,
'a Child table and a ParentChild relation between them.
'There are six combo boxes, two parents and four children
'cb_CP has one child, cb_EType has three
'All children use identical code to obtain their data
'Only cb_CRR is not working
Dim ds_CP As DataSet = Me.GetDataSet_CP()
Dim ds_EType As DataSet = Me.GetDataSet_EType()
Dim ds_Prov As DataSet = Me.GetDataSet_Prov()
Dim ds_CRR As DataSet = Me.GetDataSet_CRR()
'Bind the parent sources to the parent tables.
BindingSourceCP.DataSource = ds_CP
BindingSourceCP.DataMember = "Parent_CP"
BindingSourceEType.DataSource = ds_EType
BindingSourceEType.DataMember = "Parent_EType"
BindingSourceProv.DataSource = ds_Prov
BindingSourceProv.DataMember = "Parent_EType"
BindingSourceCRR.DataSource = ds_CRR
BindingSourceCRR.DataMember = "Parent_EType"
'Bind the child sources to the relationships.
BindingSourceDiv.DataSource = BindingSourceCP
BindingSourceDiv.DataMember = "ParentChild"
BindingSourceECat.DataSource = BindingSourceEType
BindingSourceECat.DataMember = "ParentChild"
BindingSource_Prov.DataSource = BindingSourceProv
BindingSource_Prov.DataMember = "ParentChild"
BindingSource_CRR.DataSource = BindingSourceCRR
BindingSource_CRR.DataMember = "ParentChild"
'Bind the parent controls to the parent sources.
With cb_ErrorType
.DisplayMember = "Name"
.ValueMember = "ETypeID"
.DataSource = BindingSourceEType
.SelectedIndex = -1
End With
With cb_CablePartner
.DisplayMember = "CPName"
.ValueMember = "ID"
.DataSource = BindingSourceCP
.SelectedIndex = -1
End With
'Bind the child controls to the child sources.
With cb_ECat
.DisplayMember = "ErrorDiscription"
.ValueMember = "ErrorID"
.DataSource = BindingSourceECat
.SelectedIndex = -1
End With
With cb_Market
.DisplayMember = "DivName"
.ValueMember = "DivID"
.DataSource = BindingSourceDiv
.SelectedIndex = -1
End With
End Sub
Private Function GetDataSet_CRR()
If connection.State = ConnectionState.Closed Then
connection.Open()
End If
Dim ds As New DataSet
Dim parent_etype As DataTable = Me.GetParentTable_EType()
Dim child_crr As DataTable = Me.GetChildTable_CRR()
ds.Tables.Add(parent_etype)
ds.Tables.Add(child_crr)
'Add a relationship between the ID of the parent
'table and the ParentID of the child table.
ds.Relations.Add("ParentChild", _
parent_etype.Columns("EtypeID"), _
child_crr.Columns("GroupID"))
Return ds
connection.Close()
End Function
Private Function GetChildTable_CRR() As DataTable
Dim strSQL As String = "SELECT ID, [Last Name] + ', ' + [First Name] AS Name, GroupID FROM TBLadminEMPLIST WHERE JobTitle = 1"
Dim da As New SqlDataAdapter(strSQL, connection)
Dim table As New DataTable("Child_CRR")
da.Fill(table)
Return table
End Function
Private Sub cb_ErrorType_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cb_ErrorType.SelectionChangeCommitted
'Shows/hides and populates the remaining child combo boxes based on the selected value of cb_Etype
Select Case cb_ErrorType.SelectedValue
Case Is = 5
Me.CRR_Label.Visible = True
Me.CRR_Label.Enabled = True
With cb_CRR
.Visible = True
.Enabled = True
.DisplayMember = "Name"
.ValueMember = "ID"
.DataSource = BindingSource_CRR
.SelectedIndex = -1
End With
With cb_Prov
.Visible = False
.Enabled = False
End With
With Prov_Label
.Visible = False
.Enabled = False
End With
Case Is = 3
Me.Prov_Label.Visible = True
Me.Prov_Label.Enabled = True
With cb_Prov
.Visible = True
.Enabled = True
.DisplayMember = "ProvName"
.ValueMember = "ProvID"
.DataSource = BindingSource_Prov
.SelectedIndex = -1
End With
With cb_CRR
.Visible = False
.Enabled = False
End With
With CRR_Label
.Visible = False
.Enabled = False
End With
Case Is = 4
With cb_Prov
.Visible = False
.Enabled = False
End With
With Prov_Label
.Visible = False
.Enabled = False
End With
With cb_CRR
.Visible = False
.Enabled = False
End With
With CRR_Label
.Visible = False
.Enabled = False
End With
End Select
End Sub
Thanks in advance!
Zoe
"Never shall I fail my comrades, nor leave any to fall;
For we are not separate persons, but one Guardian to All."
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|