我目前正在使用 VB.NET 和 SQL Server 开发数据库系统,除了我的 CheckListBox 和其他对象之外,一切正常。
我创建了一个事件,每当我单击 DataGridView 中的一个单元格时,其中的位(数据类型)数据将显示在我的 CheckListBox 上,并根据我单击的单元格更改值。
问题是:我单击一次并根据我单击的单元格检查复选框,但是一旦我单击另一个具有不同位值的单元格,复选框不会更改,然后其余代码不会更改不工作。
这是我使用的代码示例:
Private Sub dgvMain_CellClick(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles dgvMain.CellClick
Try
/*These codes work....*/
dtpReg.Text = dgvMain.Item(1, e.RowIndex).Value
txtFirstName.Text = dgvMain.Item(2, e.RowIndex).Value
txtMiddleName.Text = dgvMain.Item(3, e.RowIndex).Value
txtLastName.Text = dgvMain.Item(4, e.RowIndex).Value
If dgvMain.Item(5, e.RowIndex).Value = True Then
optMale.Checked = True
Else
optFemale.Checked = True
End If
dtpBirthdate.Text = dgvMain.Item(6, e.RowIndex).Value
cboCivilStatus.Text = dgvMain.Item(8, e.RowIndex).Value
dtpResidency.Text = dgvMain.Item(9, e.RowIndex).Value
txtSt.Text = dgvMain.Item(10, e.RowIndex).Value
cboBrgy.Text = dgvMain.Item(11, e.RowIndex).Value
cboEducation.Text = dgvMain.Item(12, e.RowIndex).Value
chkStudy.Checked = dgvMain.Item(13, e.RowIndex).Value
chkTB.Checked = dgvMain.Item(14, e.RowIndex).Value
chkMalnourished.Checked = dgvMain.Item(15, e.RowIndex).Value
chkIllDisabled.Checked = dgvMain.Item(16, e.RowIndex).Value
chkSoloParent.Checked = dgvMain.Item(17, e.RowIndex).Value
chkActive.Checked = dgvMain.Item(19, e.RowIndex).Value
If dgvMain.Item(20, e.RowIndex).Value = "Public center/hospital" Then
optPublic.Checked = True
ElseIf dgvMain.Item(20, e.RowIndex).Value = "Private center/hospital" Then
optPrivate.Checked = True
ElseIf dgvMain.Item(20, e.RowIndex).Value = "Non-professional" Then
optNonProf.Checked = True
End If
txtTelephone.Text = dgvMain.Item(21, e.RowIndex).Value
txtMobile.Text = dgvMain.Item(22, e.RowIndex).Value
txtEmail.Text = dgvMain.Item(23, e.RowIndex).Value
/*Unemployed ----> This is where the CheckListBox problem occurs*/
If dgvMain.Item(24, e.RowIndex).Value = True Then
clbUnemployed.SetItemCheckState(0, CheckState.Checked)
Else
clbUnemployed.SetItemCheckState(0, CheckState.Unchecked)
End If
If dgvMain.Item(25, e.RowIndex).Value = True Then
clbUnemployed.SetItemCheckState(1, CheckState.Checked)
Else
clbUnemployed.SetItemCheckState(1, CheckState.Unchecked)
End If
If dgvMain.Item(26, e.RowIndex).Value = True Then
clbUnemployed.SetItemCheckState(2, CheckState.Checked)
Else
clbUnemployed.SetItemCheckState(2, CheckState.Unchecked)
End If
If dgvMain.Item(27, e.RowIndex).Value = True Then
clbUnemployed.SetItemCheckState(3, CheckState.Checked)
Else
clbUnemployed.SetItemCheckState(3, CheckState.Unchecked)
End If
If dgvMain.Item(28, e.RowIndex).Value = True Then
clbUnemployed.SetItemCheckState(4, CheckState.Checked)
Else
clbUnemployed.SetItemCheckState(4, CheckState.Unchecked)
End If
If dgvMain.Item(29, e.RowIndex).Value = True Then
clbUnemployed.SetItemCheckState(5, CheckState.Checked)
Else
clbUnemployed.SetItemCheckState(5, CheckState.Unchecked)
End If
If dgvMain.Item(30, e.RowIndex).Value = True Then
clbUnemployed.SetItemCheckState(6, CheckState.Checked)
Else
clbUnemployed.SetItemCheckState(6, CheckState.Unchecked)
End If
If dgvMain.Item(31, e.RowIndex).Value = True Then
clbUnemployed.SetItemCheckState(7, CheckState.Checked)
Else
clbUnemployed.SetItemCheckState(7, CheckState.Unchecked)
End If
If dgvMain.Item(32, e.RowIndex).Value = True Then
clbUnemployed.SetItemCheckState(8, CheckState.Checked)
Else
clbUnemployed.SetItemCheckState(8, CheckState.Unchecked)
End If
If dgvMain.Item(33, e.RowIndex).Value = True Then
clbUnemployed.SetItemCheckState(9, CheckState.Checked)
Else
clbUnemployed.SetItemCheckState(9, CheckState.Unchecked)
End If
If dgvMain.Item(34, e.RowIndex).Value = True Then
clbUnemployed.SetItemCheckState(10, CheckState.Checked)
Else
clbUnemployed.SetItemCheckState(10, CheckState.Unchecked)
End If
If dgvMain.Item(35, e.RowIndex).Value = True Then
clbUnemployed.SetItemCheckState(11, CheckState.Checked)
Else
clbUnemployed.SetItemCheckState(11, CheckState.Unchecked)
End If
If dgvMain.Item(36, e.RowIndex).Value = True Then
clbUnemployed.SetItemCheckState(12, CheckState.Checked)
Else
clbUnemployed.SetItemCheckState(12, CheckState.Unchecked)
End If
/*Employment ---> the code after this doesn't work. Text doesn't display. Not one RadioButton checked. No picture on the picturebox. Why?*/
cboIndustry.Text = dgvMain.Item(37, e.RowIndex).Value
txtSalary.Text = dgvMain.Item(38, e.RowIndex).Value
cboJobStatus.Text = dgvMain.Item(39, e.RowIndex).Value
If dgvMain.Item(40, e.RowIndex).Value = True Then
optGyes.Checked = True
Else
optGno.Checked = True
End If
txtBrgySubd.Text = dgvMain.Item(41, e.RowIndex).Value
txtCityMunicipality.Text = dgvMain.Item(42, e.RowIndex).Value
txtProvince.Text = dgvMain.Item(43, e.RowIndex).Value
Dim ms As New MemoryStream(changephoto(CInt(dgvMain.SelectedCells(0).Value)))
PictureBox1.Image = Image.FromStream(ms)
Catch ex As Exception
End Try
End Sub