İçeriğe geç
ShiftDelete.Net
Haber ara/ SDN'ye SorGiriş
Haber Akışı SDNTV İnceleme Forum Yapay Zeka Akıllı Telefon Elektrikli Otomobil Oyun ShiftDelete.Net Global Teknoloji Haberleri Mobil Otomobil Donanım Savunma Bilim Sosyal Medya İnternet Giyilebilir Teknoloji Rehber Ürünler Son dakika Yazarlar
  1. Ana sayfa
  2. Topluluk
  3. Programlama
  4. Programlama Dilleri
Programlama Dilleri

Checbox

ivank0wsi05.12.20132 cevap942 görüntüleme
2012'den beri166 mesaj
#1

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)
Cevaplar
2011'den beri505 mesaj
#2
Eğer işine yarar ise vb.net te söylemek istediğini şu şekilde yapabilirsin.

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
ivank0wsi Konuyu açan
2012'den beri166 mesaj
#3
Bir yerdeki kod işime yaradı :)
Teşekkür ederim.
If DataGridView1(3, r).Value = True Then
DataGridView1.Rows(r).DefaultCellStyle.BackColor = Color.Red
End If

Cevabını yaz

Cevap yazmak için giriş yap ya da üye ol. Eski forum kullanıcı adın ve parolanla girebilirsin.