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 MyGetColorRowCo l(int row, int col)
{
// just conditionally set colors based on row, col values...
short number = 0;
short retval = 0;
Color c = Color.PaleGolde nrod;
if (col == 0)
{
number = array[cIndex];
retval = GetIfInChannelO rNot(code, number);
if(retval==0)
{
c = Color.LightGree n;
}
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 delegateGetColo rRowCol(int row, int col);
public class DataGridColored TextBoxColumn : DataGridTextBox Column
{
private delegateGetColo rRowCol _getColorRowCol ;
private int _column;
public DataGridColored TextBoxColumn(d elegateGetColor RowCol
getcolorRowCol, int column)
{
_getColorRowCol = getcolorRowCol;
_column = column;
}
protected override void Paint(System.Dr awing.Graphics g,
System.Drawing. Rectangle bounds, System.Windows. Forms.CurrencyM anager
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(_get ColorRowCol(row Num, this._column));
foreBrush = new SolidBrush(Colo r.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);
}
}
} 1 6278
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.co m
"James" <ja************ *****@yahoo.com .au> wrote in message
news:e6******** *************** ***@posting.goo gle.com... 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 MyGetColorRowCo l(int row, int col) { // just conditionally set colors based on row, col values...
short number = 0;
short retval = 0; Color c = Color.PaleGolde nrod;
if (col == 0) { number = array[cIndex];
retval = GetIfInChannelO rNot(code, number);
if(retval==0) { c = Color.LightGree n; }
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 delegateGetColo rRowCol(int row, int col);
public class DataGridColored TextBoxColumn : DataGridTextBox Column { private delegateGetColo rRowCol _getColorRowCol ; private int _column;
public DataGridColored TextBoxColumn(d elegateGetColor RowCol getcolorRowCol, int column) { _getColorRowCol = getcolorRowCol; _column = column; }
protected override void Paint(System.Dr awing.Graphics g, System.Drawing. Rectangle bounds, System.Windows. Forms.CurrencyM anager 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(_get ColorRowCol(row Num, this._column));
foreBrush = new SolidBrush(Colo r.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); } } } This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 date, name, address etc) about the selected row in
the datagrid...
My problem is when I enter a new record in the details tabpage (saves data
to database), and go back to the datagrid. Only the data from the PM-table
|
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 order to get information for,
everything is updated with the new data except the cell in the grid that was
selected. This behavior does not occur when a table style is not applied to
the datagrid.
How do I refresh the datagrid so that the cell in...
|
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 in the correct
order which works fine if the dataGrid.dataSource = "ArrayList", but it
doesn't work for my IBindingList wrapper.
If i bind the datasource to the arraylist method then the
ListChangedEventHandler is never invoked and my grid only...
|
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 the best method? Do you
have a sample of how to do this?
|
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 button that inserts a new row in the SQL table and then
refresh the datagrid.
| |
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 which contains a datagridlisting attendees for the meeting. On this form there is abutton which takes the user to a new form to add between 1 and 5guests. Once the guests have been added the system takes theuser back to the booking form via a piece...
|
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) so after the change the datagrid
does'nt refresh the image because her name did not change.
My question is : Is there a way to "refresh" the datagrid after the edit
function, to refresh the image ?
|
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 the file to a folder, and
then I read it back into the dataset using the dataset1.readxml. Up to this
point, everything works wonderfully. The query executes, the dataset gets
populated, and I get the results displayed in the datagrid.
|
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 Datagrid on my first Tab has a horizontal scrollbar automatically
drawn because the table is too wide, and I switch to the other tab and
resize the form, when I switch back to the first tab, the horizontal
scrollbar on the datagrid is in the same...
|
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 cell or move the
scrollbar of the datagrid... :(
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |