Why not color?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm writing a program in VB .NET 2k3, I have a datagrid bound to a database
(Access 2002). Does anyone have info or know where I can go to change the
color of a row based on the value in one column? I have found stuff on
alternating colors and all that good stuff but nothing that I need. Thanks
 
Hi Brix,
Have a look at: http://64.78.52.104/FAQ/WinForms/default.asp
under the datagrid section.

Item 5.14 might be helpful

Doug

brix_zx2 said:
I'm writing a program in VB .NET 2k3, I have a datagrid bound to a database
(Access 2002). Does anyone have info or know where I can go to change the
color of a row based on the value in one column? I have found stuff on
alternating colors and all that good stuff but nothing that I need.
Thanks
 
It'd be nice to have conditional formatting as found in Access, wouldn't
it? :) Thankfully there's another way.

You can attach a handler to the ItemDataBound event of the DataGrid
class. This event is fired once for each row in your datagrid. Check the
appropriate field, and if it matches your requirements, colour the
entire row.

---
Private Sub OnItemDataBound(Sender as Object, E as
DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If CType(e.Item.DataItem, DataRowView)("YourColumn") = 3 Then
E.Item.BackColor = KnownColor.AliceBlue
End IF
End Sub
 
brix_zx2 said:
I'm writing a program in VB .NET 2k3, I have a datagrid bound to a
database
(Access 2002). Does anyone have info or know where I can go to change the
color of a row based on the value in one column?

(Syncfusion links may be slow...)

5.14 How do I color a individual cell depending upon its value or some
external method?
<URL:http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q745q>

5.67 How can I change the font used in a grid cell on a cell by cell or row
by row basis?
<URL:http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q927q>

Changing the background color of cells in a DataGrid
<URL:http://www.codeproject.com/csharp/custom_datagridcolumnstyl.asp>

<URL:http://www.google.de/[email protected]>
 
When I try above code, I get the following error. 'Open Files' is the
name of one of my colums? - Any Ideas?

ERRO: Object reference not set to an instance of an object.

Private Sub OnItemDataBound(ByVal Sender As Object, ByVal E As
DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If CType(E.Item.DataItem, DataRowView)("Open Files") =
"1" Then
E.Item.BackColor = Drawing.Color.Brown
End If
End Sub
 
When I try above code, I get the following error. 'Open Files' is the
name of one of my colums? - Any Ideas?

ERRO: Object reference not set to an instance of an object.

Private Sub OnItemDataBound(ByVal Sender As Object, ByVal E As
DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If CType(E.Item.DataItem, DataRowView)("Open Files") =
"1" Then
E.Item.BackColor = Drawing.Color.Brown
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top