Click here to Skip to main content
14,635,966 members
Rate this:
Please Sign up or sign in to vote.
please help im newbie in programming im using and sql

i want to highlight with color cyan the value (1) for deletion i dont want to delete data instead i use to highlight it as way of deletion in when i stop and re run again the program the highlighted data was unhighlighted

this is my code:

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

        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)
            objRow.DefaultCellStyle.BackColor = Color.Cyan

    End Using
 End sub

can anyone help me in this kind of program thanks for consideration thanks in advance
Updated 31-Aug-13 23:57pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

The color of a DataGridView row is not automatically perpetuated into the database. You have to update a column in the database table that marks a row as "deleted". When you subsequently retrieve the data, you must check the value of the "deleted" column and then set the color in the DataGridView row for that data row to indicate that it is a deleted row.
Rate this:
Please Sign up or sign in to vote.

Solution 2

thats what i did but it doesnt work
Dave Kreskowiak 1-Sep-13 11:28am
It "doesn't work" because you would normally set the color of each row while the DGV is being painted, not when you're processing records.

I believe you're looking for the CellFormatting event of the DGV. You can find an example here:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100