Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

VB
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

thats what i did but it doesnt work
 
Share this answer
 
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
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900