
Checkboxa tıkladığımız zaman o satırı herhangi renge boyucak.
Formu kapatsak bile ordaki renk kaybolmıcak. Bunu nasıl yapa bilirim? Yardımcı olabilcek var mı? (c# yazıyorum)
Akış

Imports System
Imports System.Windows.Forms
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.ColumnCount = 3
DataGridView1.Columns(0).Name = "Product ID"
DataGridView1.Columns(1).Name = "Product Name"
DataGridView1.Columns(2).Name = "Product_Price"
Dim row As String() = New String() {"1", "Product 1", "1000"}
DataGridView1.Rows.Add(row)
row = New String() {"2", "Product 2", "2000"}
DataGridView1.Rows.Add(row)
row = New String() {"3", "Product 3", "3000"}
DataGridView1.Rows.Add(row)
row = New String() {"4", "Product 4", "4000"}
DataGridView1.Rows.Add(row)
Dim chk As New DataGridViewCheckBoxColumn()
DataGridView1.Columns.Add(chk)
chk.HeaderText = "Check Data"
chk.Name = "chk"
DataGridView1.Rows(2).Cells(3).Value = True
HighlightCheckBox()
End Sub
Private Sub HighlightCheckBox()
For r As Integer = 0 To DataGridView1.RowCount - 1
If DataGridView1(3, r).Value = True Then
DataGridView1.Rows(r).DefaultCellStyle.BackColor = Color.Red
End If
Next
End Sub
Private Sub EndEditMode1(sender As System.Object, e As MouseEventArgs) Handles DataGridView1.MouseUp
DataGridView1.EndEdit()
End Sub
Private Sub DataGridCellValueChanged(sender As DataGridView, e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
If e.RowIndex = -1 Then Exit Sub
Dim cb As DataGridViewCheckBoxCell = TryCast(DataGridView1(e.ColumnIndex, e.RowIndex), DataGridViewCheckBoxCell)
If cb IsNot Nothing Then
If cb.Value = True Then
DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Red
Else
DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.White
End If
End If
End Sub
End Class
Çerez tercihleriniz Sitenin çalışması için zorunlu çerezler kullanılır. Ölçüm ve reklam çerezleri yalnız onay verirseniz çalışır. Ayrıntılar