DataGridview update and Datagridview refresh

sanjeewa.nibm

Member
Joined
Oct 8, 2014
Messages
5
Programming Experience
3-5
What would be the similarities and differences in DataGridview.Update() and Datagridview.Refresh() methods

What are the places to use DataGridview.Update() and Datagridview.Refresh()

I'm little confused
 
It's got nothing specifically to do with the DataGridView class. Update and Refresh are methods of the Control class, so all controls have those methods. To understand what they do, you need to throw the Invalidate method and Paint event into the mix as well.

With GDI+ in Windows Forms, controls are getting repainted on screen quite often. Each time, a Paint event is raised. When the state of a control changes, you won't actually see the change until the control is repainted.

The actual painting of pixels to the screen is quite slow and that's why you sometimes see flickering. For that reason, it's desirable to repaint as small an area as possible each time. The Invalidate method tells the control what area or areas it needs to repaint. If you call Invalidate with no parameters then the entire control surface will be repainted on the next Paint event. If you call it with a parameter then just the specified area will be repainted. You can call Invalidate multiple times per Paint event to repaint composite areas. The Update method forces all invalidated areas to be repainted immediately. The Refresh method simply calls Invalidate with no parameters and Update.

So, Invalidate specifies an area to repaint on the next Paint event, Update repaints all invalidated areas immediately and Refresh repaints the entire control immediately.

Now, why do you think you need to call either on a DataGridView? Normally you would only have to when you were doing your own GDI+ drawing and even then not necessarily.
 
I'm referring to datagridview1.update() and datagrdview1.refresh() methods calling after the data source is set , what would be the best sequence of calling above 2 methods, what is the correct way

datagridview1.DataSource = new List.......
datagridview1.Refresh();

or

datagridview1.DataSource = new List.......
datagridview1.Update();

or else when to use datagridview1.Update() or datagridview1.Refresh();

what is the underlying theory behind the Refresh and update methods calling , since it is bit confusing
 
I already explained what they do. Why would you need to call either in that situation? I'll answer that question myself: there is no reason to call either. Just bind the data to the grid and you're done.
 
Refresh will repaint the whole datagrid

Update will repaint Only the invalid Parts

Both are Not related to the bound Data or the datasource (Refresh does not reload the Data from Source,Update will not Save the changed Data to the Source)

For everything else about both methods ... Read the answer from jmcilhinney ... It explains exactly what These methods are doin.

Also their usage... U shouldn't need to call the One or the other (except u disabled the eventhandling of your Control)
 
i am agree with tuma.
if you have small application, its not a big deal. but if you have big application and it has a big traffic network, it will lag to refresh your data.
think about it. thanks
 
I already explained what they do. Why would you need to call either in that situation? I'll answer that question myself: there is no reason to call either. Just bind the data to the grid and you're done.
Your comment saved lots of time since I was using Refresh after updating my DataTable which is set as Datasource to my datagridview and I was keep getting NullReferenceException error. Thanks alot
 

Latest posts

Back
Top Bottom