473,320 Members | 1,848 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,320 software developers and data experts.

DataGrid Display

What would be the best way to make change how the DataGrid displays data
based on the values of the dataset bound to it? I know I can create
DataGridTableStyles, but this really doesn't seem to be affected by the
data. For example, in the grid itself I have set alternating color to a
different color so alternating rows are different colors, but I want to add
a third color based on a field value of the dataset.

The dataset and the grid are programmtically created, not through the visual
design interface.
Sep 22 '05 #1
4 1426
You need to catch individual cell and you can check the value for it.
depending on the value you can set the color for it. you can get
individual column through tablystyle and check individual cell value..

HTH


JSheble wrote:
What would be the best way to make change how the DataGrid displays data
based on the values of the dataset bound to it? I know I can create
DataGridTableStyles, but this really doesn't seem to be affected by the
data. For example, in the grid itself I have set alternating color to a
different color so alternating rows are different colors, but I want to add
a third color based on a field value of the dataset.

The dataset and the grid are programmtically created, not through the visual
design interface.

Sep 23 '05 #2
JSheble,

Maybe helps this sample on our website you.

http://www.windowsformsdatagridhelp....4-5967be300f0a

I hope this helps,

Cor
Sep 23 '05 #3
I'm assuming then that I have to loop through the datagrid in order to
accomplish this, but I can see no obvious way of looping through all the
rows of the datagrid... I also see no real events for such as when a new
row is added or anything else like that... How would I do this?

"Deep Silent Ocean" <oc**********@gmail.com> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
You need to catch individual cell and you can check the value for it.
depending on the value you can set the color for it. you can get
individual column through tablystyle and check individual cell value..

HTH


JSheble wrote:
What would be the best way to make change how the DataGrid displays data
based on the values of the dataset bound to it? I know I can create
DataGridTableStyles, but this really doesn't seem to be affected by the
data. For example, in the grid itself I have set alternating color to a
different color so alternating rows are different colors, but I want to
add a third color based on a field value of the dataset.

The dataset and the grid are programmtically created, not through the
visual design interface.

Sep 23 '05 #4
Digit
4
I think this is what u need :
You make a new class who inherits from the System.Windows.Forms.DataGridTextBoxColumn

The only thing you change is the Paint event.

this is e.g. what u can do :
public class TestColumn : System.Windows.Forms.DataGridTextBoxColumn
{
public TestColumn()
{
//
// TODO: Add constructor logic here
//
}
protected override void Paint (
System.Drawing.Graphics Graph,
System.Drawing.Rectangle Bounds,
System.Windows.Forms.CurrencyManager Source,
int RowNr,
System.Drawing.Brush BackBrush,
System.Drawing.Brush ForeBrush,
bool AlignToRight)
{
DataRowView rowView = (DataRowView)Source.List[RowNr];
if (rowView["MyTestCol"]!=null)
{
string MyString = rowView["MyTestCol"].ToString();
switch (MyString)
{
case "1" :
ForeBrush=Brushes.Green;
break;
case "2" :
ForeBrush=Brushes.Black;
break;
case "3" :
ForeBrush=Brushes.DarkGreen;
break;
case "4" :
ForeBrush=Brushes.Brown;
break;
case "5" :
ForeBrush=Brushes.DarkSeaGreen;
break;
case "6" :
ForeBrush=Brushes.DarkSlateGray;
break;
default :
ForeBrush=Brushes.Black;
break;
}
}

base.Paint(Graph, Bounds,Source,RowNr,BackBrush,ForeBrush,AlignToRig ht);
}
}

It's a fast copy paste so there might be some "strange things" in the code :)

The next thing to do is something like this :
DataGridColumnStyle MyColumnStyle;
// Datum
MyColumnStyle = new TestColumn();
((DataGridTextBoxColumn)MyColumnStyle).Format="dd/MM/yyyy";
MyColumnStyle.MappingName="DatumVerrichting";
MyColumnStyle.HeaderText="Date";
MyDataGridTableStyleProductHistory.GridColumnStyle s.Add(MyColumnStyle);


It's my first reply so I hope this look better on the site then now in this box. Hope it helps at least ;)
Sep 28 '05 #5

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

Similar topics

3
by: Diego TERCERO | last post by:
Hi... I'm working on a tool for editing text resources for a family of software product my company produces. These text resources are found in a SQL Server database, in a table called...
12
by: Daniel Walzenbach | last post by:
Hi, I want to display a Label in a DataGrid according to some condition. I therefore check whether the condition is true in the ItemDateBound EventHandler of the DataGrid. Unfortunately the...
7
by: CanoeGuy | last post by:
I have been trying for the last two weeks to display a dynamic DataGrid. The data that I'm pulling from a SQL Server DB will have whole columns that will be either NULL or 0. I want to display...
7
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values. To make the thing complicated, one of the...
5
by: rn5a | last post by:
In my application, I want to populate all the directories & files existing in a directory on the server in a DataGrid. To ensure that all the directories get listed first followed by all the files,...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.