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

        Next
    End Using
 End sub
        con.Close()


can anyone help me in this kind of program thanks for consideration thanks in advance
Posted
Updated 31-Aug-13 23:57pm
v3
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
   
Comments
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: http://msdn.microsoft.com/en-us/library/z1cc356h.aspx

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