我datagridview
在 vb.Net 2008 中创建了一个带有组合框的控件。在下面的代码中,我检索多行数据并配置我datagrid
以正确显示数据。datagrid
对于返回的所有行,我可以毫无问题地填充每一行的组合框。
当我在检索特定记录的数据时尝试自动选择值时,所有组合框都错误地填充了相同的值。
在下面的代码中,“填充网格组合”代码表示我如何将值加载到组合框中。“填充特定记录”代码是我认为我遇到问题的地方。为什么所有记录的组合框都返回相同的值?我知道我的循环是正确的,因为非组合框已正确填充。
'Populate the Grid Combo
conCombo.Open(sConnectionString)
'Populate the Referral Reason combo box
sSQL = "SELECT Referral_Reason_Id, Referral_Reason FROM Referral_Reason WHERE DELETED = FALSE ORDER BY SortOrder"
cmdCombo = New ADODB.Command
cmdCombo.ActiveConnection = conCombo
cmdCombo.CommandText = sSQL
rsCombo = cmdCombo.Execute
i = 0
Do While i < dgPPV.RowCount
Do While Not rsCombo.EOF
Dim dgvcc As DataGridViewComboBoxCell
dgvcc = dgPPV.Rows(i).Cells(3)
dgvcc.Items.Add(New MyListItem(rsCombo.Fields(1).Value, rsCombo.Fields(0).Value))
rsCombo.MoveNext()
Loop
rsCombo.MoveFirst()
i = i + 1
Loop
If rsCombo.State Then rsCombo.Close()
If conCombo.State Then conCombo.Close()
If cmdCombo.State Then cmdCombo.ActiveConnection = Nothing
'Populate specific record
Sub GetPPVGridData()
Dim i As Integer
CloseConnectionString()
con.Open(sConnectionString)
sSQL = "SELECT Policy.PolicyDescription, Referral_Reason.Referral_Reason, ERS_Outcome.Outcome_Description, Audit_Outcome.Comment "
sSQL = sSQL & "FROM ((Audit_Outcome INNER JOIN Referral_Reason ON Audit_Outcome.Referral_Reason_Id = Referral_Reason.Referral_Reason_Id) INNER JOIN Policy ON Audit_Outcome.Policy_Id = Policy.Policy_ID) INNER JOIN ERS_Outcome ON Audit_Outcome.Outcome_Id = ERS_Outcome.Outcome_Id "
sSQL = sSQL & "WHERE Audit_Outcome.Referral_Id = " & lblReferralId.Text
cmd = New ADODB.Command
cmd.ActiveConnection = con
cmd.CommandText = sSQL
rs = cmd.Execute
Do While Not rs.EOF
For i = 0 To dgPPV.RowCount - 1
If dgPPV.Rows(i).Cells("dgPPVDescription").Value = rs.Fields(0).Value Then
dgPPV.Rows(i).Cells("dgCheckPPV").Value = True
dgPPV.Rows(i).Cells("dgPPVDescription").Value = rs.Fields(0).Value
dgPPV.Rows(i).Cells("dgPPVReferralReason").Value = rs.Fields(1).Value
dgPPV.Rows(i).Cells("dgPPVOutcome").Value = rs.Fields(2).Value
dgPPV.Rows(i).Cells("dgPPVComment").Value = rs.Fields(3).Value
End If
Next
rs.MoveNext()
Loop
CloseConnectionString()
End Sub
任何意见是极大的赞赏!