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

DataGrid Cell Color Defaults On Click

Hi all,

I extended the DataGridTextBoxColmun to be able to color an individual cell
in my datagrid. It works fine, but when I click on a cell, all the colored
cells in that row get the default color again. That's not what I intended.
The colored cells should stay colored, even when I click on them. What am I
doing wrong?

Thanks in advance,
Frederik

*************************
** start derived class **
*************************
public class DataGridTextBoxColumnEx :
DataGridTextBoxColumn
{
public void RowPaint(System.Data.DataTable dt,
Graphics g, Rectangle bounds, int rowNum)
{
CurrencyManager source =
(CurrencyManager)frmMain.ActiveForm.BindingContext[dt];
Brush backBrush = new SolidBrush(Color.DarkSalmon);
Brush foreBrush = new SolidBrush(Color.Black);
base.Paint(g, bounds, source, rowNum, backBrush,
foreBrush, false);
}
}
************************
** stop derived class **
************************
******************************************
** start method that calls Paint method **
******************************************
private void btnVerbeter_Click(object sender,
System.EventArgs e)
{
// grip krijgen op de achterliggende tabel
DataTable dt = ((DataView)DGridOpvraging.DataSource).Table;
// rechthoek van de cel
Rectangle cellRect;
// alle cellen doorlopen
for(int i = 0; i < dt.Rows.Count; i++)
{
if (!dt.Rows[i][2].ToString().Trim().Equals(
DGridOpvraging[i, 1].ToString().Trim()))
{
cellRect = DGridOpvraging.GetCellBounds(i, 1);
// Get the Graphics object for the form.
Graphics gr = DGridOpvraging.CreateGraphics();
// Paint methode aanroepen om de cel te kleuren
secondCol.RowPaint(dt, gr, cellRect, i);
}
}
}
*****************************************
** stop method that calls Paint method **
*****************************************
Nov 16 '05 #1
1 1380
Frederik,

I'm not quite sure I understand what you are trying to do. However,
based on what I have seen, I don't think that you are indicating the
re-paint correctly. If anything, in your button event handler, you should
call Invalidate on the data grid, which will force a repaint. Before you do
that, however, you should set whatever properties you need to in order for
the override of the Paint to correctly paint itself.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frederik" <ae************@hotmail.com> wrote in message
news:uQ*************@TK2MSFTNGP09.phx.gbl...
Hi all,

I extended the DataGridTextBoxColmun to be able to color an individual
cell in my datagrid. It works fine, but when I click on a cell, all the
colored cells in that row get the default color again. That's not what I
intended. The colored cells should stay colored, even when I click on
them. What am I doing wrong?

Thanks in advance,
Frederik

*************************
** start derived class **
*************************
public class DataGridTextBoxColumnEx :
DataGridTextBoxColumn
{
public void RowPaint(System.Data.DataTable dt,
Graphics g, Rectangle bounds, int rowNum)
{
CurrencyManager source =
(CurrencyManager)frmMain.ActiveForm.BindingContext[dt];
Brush backBrush = new SolidBrush(Color.DarkSalmon);
Brush foreBrush = new SolidBrush(Color.Black);
base.Paint(g, bounds, source, rowNum, backBrush,
foreBrush, false);
}
}
************************
** stop derived class **
************************
******************************************
** start method that calls Paint method **
******************************************
private void btnVerbeter_Click(object sender,
System.EventArgs e)
{
// grip krijgen op de achterliggende tabel
DataTable dt = ((DataView)DGridOpvraging.DataSource).Table;
// rechthoek van de cel
Rectangle cellRect;
// alle cellen doorlopen
for(int i = 0; i < dt.Rows.Count; i++)
{
if (!dt.Rows[i][2].ToString().Trim().Equals(
DGridOpvraging[i, 1].ToString().Trim()))
{
cellRect = DGridOpvraging.GetCellBounds(i, 1);
// Get the Graphics object for the form.
Graphics gr = DGridOpvraging.CreateGraphics();
// Paint methode aanroepen om de cel te kleuren
secondCol.RowPaint(dt, gr, cellRect, i);
}
}
}
*****************************************
** stop method that calls Paint method **
*****************************************

Nov 16 '05 #2

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

Similar topics

2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
0
by: elime | last post by:
Hi all I have a strange behaving on some PC with my DataGrid. It only occurs on some PC, on others it works perfectly fine. ->(same ..net version installed) it's very confusing. starting...
2
by: Daniel Walzenbach | last post by:
Hi, I created an ASP.NET Datagrid where a single row can be selected by clicking anywhere on the row (according to...
13
by: pmcguire | last post by:
I have a DataGrid control for which I have also created several new extended DataGridColumnStyles. They behave pretty nicely, but I can't figure out how to implement Selected Item formatting for...
4
by: skOOb33 | last post by:
I successfully autosized the columns and rows on my Datagrid, and am now facing another issue. Having the sorting ability by clicking the column headers is key, but when I do that, it resizes all...
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
5
by: Nick | last post by:
Hey guys, I have 2 events on a windows forms datagrid, the mouse move as well as the double click events. What's happening is that when I double click on a row in the grid, the mouse move event...
3
by: Ryan Liu | last post by:
Can someone give a sample to prevent a row from being deleted in a datatable? I tried e.Row.RejectChanges(); in dt_RowDeleting() but seems does not work. I need verify if there other data...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.