473,387 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Setting Foreground Color Property at Row Level in Datagrid

I think I am using the proper terminology here ... I am using VB 2003 and
have a DataGrid to which I then attach a TableStyle ... then I set the
properties of the TableStyle (BackColor, HeaderBackColor, etc.) ... then I
create several DataGridTextBoxColumns and set their properties (MappingName,
Width, Alignment, etc.) ... then I add these columns to the DataGridStyle.
Next, using the MappingNames I add the columns to a DataTable ... then I add
the DataTable to a DataSet ... and finally bind the DataSet to the DataGrid
so the user can see it (whew!). All of this seems incredibly complicated
when all I want to do is display some stuff in tabular form with some column
headers.

In any event, I would like to set the foreground color of a displayed row
based on the value of a particular item in the row ... yet with all these
constructs (table styles, textbox columns, data tables, etc.) I cannot
figure out how to do it. Can someone help me understand how to do this ...
or point me to an article that will help?

Thanks very much.
Mar 15 '06 #1
3 2647
fripper wrote:
I think I am using the proper terminology here ... I am using VB 2003 and
have a DataGrid to which I then attach a TableStyle ... then I set the
properties of the TableStyle (BackColor, HeaderBackColor, etc.) ... then I
create several DataGridTextBoxColumns and set their properties (MappingName,
Width, Alignment, etc.) ... then I add these columns to the DataGridStyle.
Next, using the MappingNames I add the columns to a DataTable ... then I add
the DataTable to a DataSet ... and finally bind the DataSet to the DataGrid
so the user can see it (whew!). All of this seems incredibly complicated
when all I want to do is display some stuff in tabular form with some column
headers.

In any event, I would like to set the foreground color of a displayed row
based on the value of a particular item in the row ... yet with all these
constructs (table styles, textbox columns, data tables, etc.) I cannot
figure out how to do it. Can someone help me understand how to do this ...
or point me to an article that will help?

Thanks very much.


Yes, your terminology is correct. I will say you could simplify it by
binding the datatable directly to the datagrid (make sure the tablename
equals the tablestyle.mappingname.) But now to your next question.

Unfortunately to do this you have to create your own
DataGridTextBoxColumns and override the onpaint method. It's not as
hard as you might think if you've never done it before. This article
walks you through it (it's in C# but the function calls are all there)

http://www.codeproject.com/csharp/Cu...ColumnStyl.asp

The important function is:

protected override sub Paint(....)

public sub
dim bdel as boolean= ctype(GetColumnValueAtRow(Source, RowNum), bool)

if bdel then
BackBrush = Brushes.Coral
else
BackBrush = Brushes.White
end if

g.FillRectangle(BackBrush, Bounds.X, Bounds.Y, Bounds.Width,
Bounds.Height)

System.Drawing.Font font = new
Font(System.Drawing.FontFamily.GenericSansSerif,
(float)8.25 )
g.DrawString( bdel.ToString(), font, Brushes.Black, Bounds.X, Bounds.Y)

end sub
Mar 15 '06 #2
Thanks Chris ... that is very helpful. I have modified the program to bind
the datatable directly to the datagrid ... at least that eliminates one
unnecessary construct in the process.

Now I will see about adding my own onPaint method. It's a slow process but
I am gradually becoming more familiar with VB .Net. I have just installed
VB 2005 but have not yet ported this program over to it.

Thanks again.
"Chris" <no@spam.com> wrote in message
news:uk**************@tk2msftngp13.phx.gbl...
fripper wrote:
I think I am using the proper terminology here ... I am using VB 2003 and
have a DataGrid to which I then attach a TableStyle ... then I set the
properties of the TableStyle (BackColor, HeaderBackColor, etc.) ... then
I create several DataGridTextBoxColumns and set their properties
(MappingName, Width, Alignment, etc.) ... then I add these columns to the
DataGridStyle. Next, using the MappingNames I add the columns to a
DataTable ... then I add the DataTable to a DataSet ... and finally bind
the DataSet to the DataGrid so the user can see it (whew!). All of this
seems incredibly complicated when all I want to do is display some stuff
in tabular form with some column headers.

In any event, I would like to set the foreground color of a displayed row
based on the value of a particular item in the row ... yet with all these
constructs (table styles, textbox columns, data tables, etc.) I cannot
figure out how to do it. Can someone help me understand how to do this
... or point me to an article that will help?

Thanks very much.


Yes, your terminology is correct. I will say you could simplify it by
binding the datatable directly to the datagrid (make sure the tablename
equals the tablestyle.mappingname.) But now to your next question.

Unfortunately to do this you have to create your own
DataGridTextBoxColumns and override the onpaint method. It's not as hard
as you might think if you've never done it before. This article walks you
through it (it's in C# but the function calls are all there)

http://www.codeproject.com/csharp/Cu...ColumnStyl.asp

The important function is:

protected override sub Paint(....)

public sub
dim bdel as boolean= ctype(GetColumnValueAtRow(Source, RowNum), bool)

if bdel then
BackBrush = Brushes.Coral
else
BackBrush = Brushes.White
end if

g.FillRectangle(BackBrush, Bounds.X, Bounds.Y, Bounds.Width,
Bounds.Height)

System.Drawing.Font font = new
Font(System.Drawing.FontFamily.GenericSansSerif,
(float)8.25 )
g.DrawString( bdel.ToString(), font, Brushes.Black, Bounds.X,
Bounds.Y)

end sub

Mar 16 '06 #3
fripper wrote:
Thanks Chris ... that is very helpful. I have modified the program to bind
the datatable directly to the datagrid ... at least that eliminates one
unnecessary construct in the process.

Now I will see about adding my own onPaint method. It's a slow process but
I am gradually becoming more familiar with VB .Net. I have just installed
VB 2005 but have not yet ported this program over to it.

Thanks again.
"Chris" <no@spam.com> wrote in message
news:uk**************@tk2msftngp13.phx.gbl...
fripper wrote:
I think I am using the proper terminology here ... I am using VB 2003 and
have a DataGrid to which I then attach a TableStyle ... then I set the
properties of the TableStyle (BackColor, HeaderBackColor, etc.) ... then
I create several DataGridTextBoxColumns and set their properties
(MappingName, Width, Alignment, etc.) ... then I add these columns to the
DataGridStyle. Next, using the MappingNames I add the columns to a
DataTable ... then I add the DataTable to a DataSet ... and finally bind
the DataSet to the DataGrid so the user can see it (whew!). All of this
seems incredibly complicated when all I want to do is display some stuff
in tabular form with some column headers.

In any event, I would like to set the foreground color of a displayed row
based on the value of a particular item in the row ... yet with all these
constructs (table styles, textbox columns, data tables, etc.) I cannot
figure out how to do it. Can someone help me understand how to do this
... or point me to an article that will help?

Thanks very much.


Yes, your terminology is correct. I will say you could simplify it by
binding the datatable directly to the datagrid (make sure the tablename
equals the tablestyle.mappingname.) But now to your next question.

Unfortunately to do this you have to create your own
DataGridTextBoxColumns and override the onpaint method. It's not as hard
as you might think if you've never done it before. This article walks you
through it (it's in C# but the function calls are all there)

http://www.codeproject.com/csharp/Cu...ColumnStyl.asp

The important function is:

protected override sub Paint(....)

public sub
dim bdel as boolean= ctype(GetColumnValueAtRow(Source, RowNum), bool)

if bdel then
BackBrush = Brushes.Coral
else
BackBrush = Brushes.White
end if

g.FillRectangle(BackBrush, Bounds.X, Bounds.Y, Bounds.Width,
Bounds.Height)

System.Drawing.Font font = new
Font(System.Drawing.FontFamily.GenericSansSeri f,
(float)8.25 )
g.DrawString( bdel.ToString(), font, Brushes.Black, Bounds.X,
Bounds.Y)

end sub



In 2005 you can use the DataGridView which makes everything much much
easier. If you're considering the upgrade you may want to do it sooner
and switch over the control.

Note: The DataGridView is for viewing one table only, unlike the
DataGrid which can show off relationships.

Chris
Mar 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: TF | last post by:
hi, i am using a ListBox control on a windows form using VB.Net. when i set the DataSource property of the control to an ArrayList it fires following events in this order: SelectedIndexChanged...
2
by: Mervin Williams | last post by:
I am trying to set the text property of one of my labels in a data grid to the value of a text box in the same datagrid. Please help! Mervin Williams
5
by: Dennis | last post by:
I have a class that inherits from DataGrid. I can set the rowheights in a DataGrid by tappig into the "get_Datagridrows" method. However, this does not work for classes that inherit from...
6
by: cr113 | last post by:
I'm trying to set the column widths for a datagrid. You'd think it would be easy. I looked it up in google and the first thing I found looked promising: datagrid1.columns(0).width = 2000...
2
by: fripper | last post by:
After a good bit of urging from folks in this newsgroup I have begun to become familiar with the VB .Net DataGrid control as a replacement for one my favorite VB6 controls ... the FlexGrid. In any...
4
by: Rich | last post by:
Hello, I have a one datagrid that will be based on different datatables. One datatable may have 7 columns, another 15... With the tables that have more columns, I have been manually dragging...
4
by: MLH | last post by:
Setting form's Picture property to another file from within VBA doesn't repaint the form with new bitmap - for instance... Me.Picture = "c:\pics\MyNewPic.jpg" I tried Me.Repaint afterward,...
4
by: Blackbrand | last post by:
I'll start off with what i'm trying to do: i want to search my data programmatically and then jump to the row in the datagrid. My data will almost allways go out of the datagrids bounds so if the...
2
by: Iain Wilson | last post by:
Hi All I would like to set the width of the bottom line of a datagrid row at runtime. I know how to set the complete lines style color etc at runtime but I cannot figure how to change the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.