0

请帮助使用 vb.net 和 sql server 进行标记,当双击 datagridview 中的选定数据时,我希望删除的值 (1) 将以青色突出显示

这是我的代码

  Private Sub showme()

    Dim i As Integer


        For i = 0 To dgvDoctorsList.RowCount > -1
            Dim remrks = dgvDoctorsList.Rows(i).Cells(6).Value
        If remrks = "1" Then
            dgvDoctorsList.Rows(i).DefaultCellStyle.BackColor = Color.Cyan
        End If

        Next


End Sub

Private Sub dgvDoctorsList_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvDoctorsList.CellDoubleClick

    If MessageBox.Show("Are you sure want to delete this data ?", "CONFIRMATION", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then

        Dim objCmd As New SqlCommand()
        Using con As New SqlConnection("server=ACHACOSOFAMILY;database=jjasgh;integrated security=true")
            objCmd.Connection = con
            con.Open()

            For Each objRow As DataGridViewRow In dgvDoctorsList.SelectedRows
                objCmd.CommandText = "Update tbl_Doctor SET Remarks=1 where License_no=@license"

                objCmd.Parameters.AddWithValue("@license", dgvDoctorsList.CurrentRow.Cells(0).Value)
                objCmd.ExecuteNonQuery()
                showme()

            Next
        End Using
     End sub

感谢您的考虑请帮助提前谢谢

4

1 回答 1

0

如果您的双击事件运行良好,那么您必须在 RowPrepaint 事件中进行。

Private Sub dgvDoctorsList_RowPrePaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles dgvDoctorsList.RowPrePaint
    Dim x as Integer = e.RowIndex

    If dgvDoctorsList.Rows(x).Cells("remarks").Value= 1 Then
        dgvDoctorsList.Rows(x).DefaultCellStyle.BackColor = Color.Cyan
    End If
End Sub
于 2013-09-01T12:56:25.380 回答