F
Frederik
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[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 **
*****************************************
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[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 **
*****************************************