Şekil 1
Form1.vb
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'DataGridview nesnemize cbox sütunu ekliyoruz.
Dim checkbox As New DataGridViewCheckBoxColumn
With checkbox
.DataPropertyName = "CheckBox"
.HeaderText = "Sec"
.Width = 80
.Name = "cb1"
End With
DataGridView1.Columns.Add(checkbox)
Dim baglan As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Northwind.mdb;")
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select CustomerID,CompanyName,ContactName,Address,City From Customers", baglan)
Dim ds As DataSet = New DataSet()
baglan.Open()
da.Fill(ds, "Customers")
DataGridView1.DataSource = ds.Tables(0)
baglan.Close()
End Sub
Private Sub DataGridView1_RowPrePaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DataGridView1.RowPrePaint
Dim satir As DataGridViewRow = Me.DataGridView1.Rows(e.RowIndex)
If CBool(satir.Cells(0).Value) = False Then
satir.DefaultCellStyle.BackColor = Color.White
Else
'Seçili cbox ın rengini orangered, yazı rengini beyaz yapıyoruz.
satir.DefaultCellStyle.BackColor = Color.OrangeRed
satir.DefaultCellStyle.ForeColor = Color.White
End If
End Sub
End Class
0 comments:
Yorum Gönder