kiranboi
asked on
Coloring Rows in a DataGrid Depending on Contents
Hi all,
I have a DataGrid in my app which is dynamically populated from a DataSet. I have set up a TableStyle to format the columns correctly and bound this the the DataGrid. All wrks fine so far, however...
I need to color the rows of the DataGrid depending on its contents. There will be two columns in the DataGrid both with prices in them. I need my app to compare the prices for each row and color the row one color if there is a price increase or a different colour if there is a price decrease.
Anybody know I can achive this (preferably without messing up the TableStyle I already have set)
Thanks
I have a DataGrid in my app which is dynamically populated from a DataSet. I have set up a TableStyle to format the columns correctly and bound this the the DataGrid. All wrks fine so far, however...
I need to color the rows of the DataGrid depending on its contents. There will be two columns in the DataGrid both with prices in them. I need my app to compare the prices for each row and color the row one color if there is a price increase or a different colour if there is a price decrease.
Anybody know I can achive this (preferably without messing up the TableStyle I already have set)
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
catch the cellpaint event on the grid and set the grids backcolour as required, much easier (if not as good as a proper custome celltype) and what you are looking for i thinks...
sorry there is no cellpaint event for the standard datagrid.
if you can, upgrade to the datagridview (i.e. .net2) it is far superior and *has* a cell paint event.. then all you need to do is..
Private Sub DataGridView1_CellPainting (ByVal sender As Object, ByVal e As System.Windows.Forms.DataG ridViewCel lPaintingE ventArgs) Handles DataGridView1.CellPainting
DataGridView1.Columns(e.Co lumnIndex) .DefaultCe llStyle.Ba ckColor = Color.Red
End Sub
if you can, upgrade to the datagridview (i.e. .net2) it is far superior and *has* a cell paint event.. then all you need to do is..
Private Sub DataGridView1_CellPainting
DataGridView1.Columns(e.Co
End Sub
You can also take a look at the sample project I posted at the link below which will highlight every cell in a row of a datagrid if one of the values matches a given value, which should get you going in the right direction. It's basically using the same technique that iboutchkine has shown you above.
http://www.vbcity.com/forums/topic.asp?tid=127278&#RID409958
Hope it's of use
Andy(aka Skullcrusher, aka Heintalus)
http://www.vbcity.com/forums/topic.asp?tid=127278&#RID409958
Hope it's of use
Andy(aka Skullcrusher, aka Heintalus)
ASKER
lojk
that sounds ideal. Ive downloaded and installed the .NET 2.0 framework SDK but I'm not sure how I can now use this to create a DataGridView. My VB.NET still says its using .NET framework 1.1
Any ideas what I'm doing wrong?
Thanks
that sounds ideal. Ive downloaded and installed the .NET 2.0 framework SDK but I'm not sure how I can now use this to create a DataGridView. My VB.NET still says its using .NET framework 1.1
Any ideas what I'm doing wrong?
Thanks
yep only Visual Studio 2005 allows you to use .net2.0 im afraid thats why my 'if you can' comment is there, sorry i should have been a little clearer..
if you have access to that then check out my thread with Cherryex in
https://www.experts-exchange.com/questions/21964461/Conditional-Formatting-for-a-datagrid-row-winforms.html
where we discuss her problem in more detail.
Unfortunately if you cant upgrade to vs2005 then you are stuck (in every sense of the word) with the very valid examples above...
if you have access to that then check out my thread with Cherryex in
https://www.experts-exchange.com/questions/21964461/Conditional-Formatting-for-a-datagrid-row-winforms.html
where we discuss her problem in more detail.
Unfortunately if you cant upgrade to vs2005 then you are stuck (in every sense of the word) with the very valid examples above...
ASKER
lojk,
thanks for that. now i know what i need to do to upgrade properly. ive used the code example from iboutchkine to solve my problem for now so im gonna give them the points but i have already asked another question about upgrading .net framework which can be found here
https://www.experts-exchange.com/questions/21965688/Upgrading-VB-NET-to-NET-Framework-2-0-SDK.html
if you want to paste your answer there then you can have the points for that one :o)
thanks for that. now i know what i need to do to upgrade properly. ive used the code example from iboutchkine to solve my problem for now so im gonna give them the points but i have already asked another question about upgrading .net framework which can be found here
https://www.experts-exchange.com/questions/21965688/Upgrading-VB-NET-to-NET-Framework-2-0-SDK.html
if you want to paste your answer there then you can have the points for that one :o)
rather sporting of you, have done just that...
thanks :-)
thanks :-)