473,406 Members | 2,894 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,406 software developers and data experts.

DataGrid Refresh problem

I have a data grid refresh problem. I have a few columns and the first
column is data in the form of numbers. And in the form of the data
grid if I specify for example something like a code(in a text box) the
column of numbers should change colors depending on whether the number
was in the specified code(if it belongs to the code, color the cell
(first column) in Red and if not in some other color). It all works
out fine until I scroll up/down and trigger the paint event. The
changed colurs seem to be changed. I want the refreshing to be done
for all records for that column, but it seems it only refreshes parts
of the datagrid. How do I make the refreshing to be done to the whole
datagrid rather than a part of it, so I can get the original colur
change for each cell of the first column.

Code

//method to be passed into the coloumn style that determines the color
public Color MyGetColorRowCol(int row, int col)
{
// just conditionally set colors based on row, col values...

short number = 0;

short retval = 0;
Color c = Color.PaleGoldenrod;

if (col == 0)
{
number = array[cIndex];

retval = GetIfInChannelOrNot(code, number);

if(retval==0)
{
c = Color.LightGreen;
}

if(retval!=0)
{
c = Color.Red;
}

cIndex++;

if(TotalNumbers == cIndex)
{
cIndex = 0;
}

}

else
{
c = Color.LightGray;
}
return c;

}
//delegate required by custom column style

public delegate Color delegateGetColorRowCol(int row, int col);

public class DataGridColoredTextBoxColumn : DataGridTextBoxColumn
{
private delegateGetColorRowCol _getColorRowCol;
private int _column;

public DataGridColoredTextBoxColumn(delegateGetColorRowCo l
getcolorRowCol, int column)
{
_getColorRowCol = getcolorRowCol;
_column = column;
}
protected override void Paint(System.Drawing.Graphics g,
System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager
source, int rowNum, System.Drawing.Brush backBrush,
System.Drawing.Brush foreBrush, bool alignToRight)
{
// the idea is to conditionally set the foreBrush and/or backbrush
// depending upon some crireria on the cell value
// Here, we use a delegate to retrieve the color
try
{

backBrush = new SolidBrush(_getColorRowCol(rowNum, this._column));

foreBrush = new SolidBrush(Color.Black);
}

catch(Exception ex){ /* empty catch */ }
finally
{
// make sure the base class gets called to do the drawing with
// the possibly changed brushes
base.Paint(g, bounds, source, rowNum, backBrush, foreBrush,
alignToRight);
}
}
}
Nov 16 '05 #1
1 6258
James,

If you want the whole grid to be repainted, then you will want to call
the Invalidate method on the DataGrid, which will trigger a repaint of the
entire control.

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

"James" <ja*****************@yahoo.com.au> wrote in message
news:e6**************************@posting.google.c om...
I have a data grid refresh problem. I have a few columns and the first
column is data in the form of numbers. And in the form of the data
grid if I specify for example something like a code(in a text box) the
column of numbers should change colors depending on whether the number
was in the specified code(if it belongs to the code, color the cell
(first column) in Red and if not in some other color). It all works
out fine until I scroll up/down and trigger the paint event. The
changed colurs seem to be changed. I want the refreshing to be done
for all records for that column, but it seems it only refreshes parts
of the datagrid. How do I make the refreshing to be done to the whole
datagrid rather than a part of it, so I can get the original colur
change for each cell of the first column.

Code

//method to be passed into the coloumn style that determines the color
public Color MyGetColorRowCol(int row, int col)
{
// just conditionally set colors based on row, col values...

short number = 0;

short retval = 0;
Color c = Color.PaleGoldenrod;

if (col == 0)
{
number = array[cIndex];

retval = GetIfInChannelOrNot(code, number);

if(retval==0)
{
c = Color.LightGreen;
}

if(retval!=0)
{
c = Color.Red;
}

cIndex++;

if(TotalNumbers == cIndex)
{
cIndex = 0;
}

}

else
{
c = Color.LightGray;
}
return c;

}
//delegate required by custom column style

public delegate Color delegateGetColorRowCol(int row, int col);

public class DataGridColoredTextBoxColumn : DataGridTextBoxColumn
{
private delegateGetColorRowCol _getColorRowCol;
private int _column;

public DataGridColoredTextBoxColumn(delegateGetColorRowCo l
getcolorRowCol, int column)
{
_getColorRowCol = getcolorRowCol;
_column = column;
}
protected override void Paint(System.Drawing.Graphics g,
System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager
source, int rowNum, System.Drawing.Brush backBrush,
System.Drawing.Brush foreBrush, bool alignToRight)
{
// the idea is to conditionally set the foreBrush and/or backbrush
// depending upon some crireria on the cell value
// Here, we use a delegate to retrieve the color
try
{

backBrush = new SolidBrush(_getColorRowCol(rowNum, this._column));

foreBrush = new SolidBrush(Color.Black);
}

catch(Exception ex){ /* empty catch */ }
finally
{
// make sure the base class gets called to do the drawing with
// the possibly changed brushes
base.Paint(g, bounds, source, rowNum, backBrush, foreBrush,
alignToRight);
}
}
}

Nov 16 '05 #2

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

Similar topics

5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
1
by: Shawn Benson | last post by:
I have a Windows form where a user enters an order number which returns a dataset that is bound to a datagrid. The problem is when a user clicks on a cell in the datagrid, then enters another...
3
by: Matthew Woods | last post by:
Hi, is there any way to format and order the columns displayed in a datagrid bound to a class that inherits from IBindingList? i have used DataGridTableStyle and added DataGridTextBoxColumns to it...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
8
by: Inigo Jimenez | last post by:
I have an ASP .net web application installed in a Windows 2003 server. This web application has a webform that has a Datagrid. This Datagrid is filled with the data of a SQL table. I have a...
3
by: james crosthwaite via .NET 247 | last post by:
Hi, I'm pretty new to .NET and i'm having a major problem which ireally need some help with. I am developing an application for my office which allows usersto book rooms. I have a Booking Form...
1
by: Andre | last post by:
hi, In my Datagrid i have some text and a image (for each item), if i edit the image and save it to the HD there's no problem, but the image is always saved with the same name (item number.jpg)...
7
by: Juan Romero | last post by:
Hey guys, please HELP I am going nuts with the datagrid control. I cannot get the damn control to refresh. I am using soap to get information from a web service. I have an XML writer output...
1
by: Kevin Hodgson | last post by:
I'm having a strange problem with a VB.NET App, and the built in Windows.Forms.Datagrid I have a tabbed interface, and a DataGrid (along with other controls) on each of my two Tabs. If the...
2
by: Dan | last post by:
Hi, I have a Datagrid in a simple form that I programmatically modify using something like that : Me.DataGrid1(RowID, ColID) = "blablabla" But my cell wont refresh unless I click on another...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.