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. 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.
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.
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 ;)
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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
|
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...
| |