简体   繁体   English

用SQL标记vb.net

[英]flagging vb.net with sql

please help in flagging using vb.net and sql server i want the deleted value (1) will be highlight with color cyan when the selected data in datagridview is double click 请帮助使用vb.net和sql server进行标记,当双击datagridview中的选定数据时,我希望已删除的值(1)用青色突出显示

this is my code 这是我的代码

  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

thanks for consideration please help thanks in advance 感谢您的考虑,请提前帮助

If your doubleclick event working good, then you have to do it in RowPrepaint event .. 如果您的doubleclick事件运行良好,则必须在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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM