Senin, 02 Februari 2009

IDE : VS 2005, Platform : .NET 2.0,
BackColor DataGridView Columns
I'm trying to set the backcolor of the columns of a datagridview based on the text entered into a textbox(txtPosit). First of all, this code works:
Code: For Each column As DataGridViewColumn In Me.dgvMaster.Columns If column.HeaderText = Me.txtPosit.Text Then column.DefaultCellStyle.BackColor = Color.LightGray End If Next

The problem I'm having is formatting multiple columns based on the text that is NOT the name of one of the columns (This is a program to filter positions of a baseball database). One of the filter options is "Middle", and when this is selected, I would like to set the backcolor of the 2B and SS columns in the datagridview. Here's what I thought would work:
Code: If Me.txtPosit.Text = "Middle" Then
For Each column As DataGridViewColumn In Me.dgvMaster.Columns If column.HeaderText = "2B" Or column.HeaderText = "SS" Then column.DefaultCellStyle.BackColor = Color.LightGray End If Next
End If

This code provides no formatting to the columns. However, if I remove the outside IF/THEN statement, then the backcolor of both columns is changed no matter what text is entered in the textbox.
Am I approaching this the wrong way, or am I missing something?
Thanks for any help.
Rick
Edited by - rb72169 on 3/21/2008 5:34:33 AM
source :http://www.vbcity.com
-------------------------------------------------------
Trik Gambar Bergerak
http://gambar-dimouse.blogspot.com">Trik Gambar-dimouse
http://hapuspwdmysql.blogspot.com">Trik hapus pwd mysql
http://insertintodb.blogspot.com">Trik insertin to db
http://jadirootdilinux.blogspot.com">Trik jadi root dilinux
http://jam-distatus-bar.blogspot.com">Trik jam-distatus-bar
http://koneksi-kedatabase.blogspot.com">Trik Koneksi-ke database
http://koneksi-msql-php.blogspot.com">Trik Koneksi-msql-php
http://lihat-database-mysql.blogspot.com">Trik lihat-database-mysql
http://membahas-fungsi-else.blogspot.com">Trik membahas-fungsi-else
http://member-area-riaq.blogspot.com">Trik member-area