473,729 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 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);
}
}
}
Nov 16 '05 #1
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);
}
}
}

Nov 16 '05 #2

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

Similar topics

5
2595
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
1
1977
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...
3
1791
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...
3
4879
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?
8
1955
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.
3
298
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...
1
1919
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 ?
7
15441
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.
1
2268
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...
2
4570
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... :(
0
8917
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, 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...
0
8761
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,...
0
9426
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, 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...
1
9200
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,...
0
9142
tracyyun
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...
0
8148
agi2029
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...
0
4525
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...
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2163
bsmnconsultancy
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...

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.