473,403 Members | 2,323 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,403 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 1429
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.