This is a migrated thread and some comments may be shown as answers.

RadGridView : Refresh problem

12 Answers 1250 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jv
Top achievements
Rank 1
jv asked on 06 Oct 2009, 11:16 AM
Hi.

I'm using RadControls for WinForms Q3 2008 SP2 and i always have problems to refresh the RadGridView.

I have a class ObjectInfo with some properties.

I have a form with a RadGridView and a BindingList :

private BindingList<ObjectInfo> _listObjects;

In Form1_Load :
radGrid.DataSource=_listObjects;

When I change one property of an object of _listObjects, the Refresh method doesn't work, the only way to refresh the GridView is to do :

radGrid.DataSource = null;
radGrid.DataSource = _listObjects;

Is there any other solution ? Because it takes time because there are many rows, rows are formatted with different colors depending on the value of a column (Event RowFormatting), and the grid scrolls on the first row so I have to call the EnsureVisible method because the user can't see anymore the selected row. And also I have to redefine columns (Width, FormatString for Date for example, etc...).

Thanks.

12 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 08 Oct 2009, 08:33 AM
Hello jv,

Your ObjectInfo class must implement INotifyPropertyChanged interface to support automatic refresh when used in RadGridView. Please view this example:

public class OBjectInfo : INotifyPropertyChanged 
    private string name; 
 
    public string Name 
    { 
        get { return name; } 
        set  
        {  
            name = value; 
            this.OnPropertyChanged("Name"); 
        } 
    } 
 
    private void OnPropertyChanged(string propertyName) 
    { 
        this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName)); 
    } 
 
    protected virtual void OnPropertyChanged(PropertyChangedEventArgs args) 
    { 
        if (this.PropertyChanged != null
        { 
            this.PropertyChanged(this, args); 
        } 
    } 
    #region INotifyPropertyChanged Members 
 
    public event PropertyChangedEventHandler PropertyChanged; 
    #endregion 

Kind regards,
Julian Benkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
jv
Top achievements
Rank 1
answered on 09 Oct 2009, 07:38 AM
It works fine, thanks for the reply.
0
jv
Top achievements
Rank 1
answered on 11 Feb 2010, 03:25 PM
Hello,

To avoid implementing INotifyPropertyChanged in all classes and call this.OnPropertyChanged in all set accessors, we finally found an easiest solution : in the CellValueChanged of the RadGridView we only write this :

RadGridView.ReadOnly = !RadGridView.ReadOnly;
RadGridView.ReadOnly = !RadGridView.ReadOnly;
0
Nick
Telerik team
answered on 11 Feb 2010, 04:39 PM
Hello jv,

Thank you for contacting us. Unfortunately, while this may work, it is certainly not the best solution as you are actually refreshing the grid using this strange shortcut. If you implement the interface, the refresh will be more accurate and you will gain performance improvement.

Do not hesitate to write us back if you have further questions.

Greetings,
Nick
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ehab
Top achievements
Rank 1
answered on 17 Jun 2012, 09:31 PM
Hi,

Why not implementing RefreshData() method in row (like notifing manualy) or somthing like that and make your users life easier ;).
I dont want implement the INotify in all my classes (DTOs) because I cant (no time) , Pleaaaaaaaaaaaaase give me a work around to force the row or the whole grid to redraw the data.  
jv work around didnt work for me


0
Ehab
Top achievements
Rank 1
answered on 18 Jun 2012, 05:24 PM
Hi,

I  found an elegant work around .
After updating row data in the data source just call   InvalidateRow() method  from the specific GridViewRowInfo.

For example:

(( IssueClass )RadGridView1.CurrentRow.DataBoundItem).Satus= "Resolved" ;
RadGridView1.CurrentRow.InvalidateRow() ; 







0
Julian Benkov
Telerik team
answered on 20 Jun 2012, 01:16 PM
Hi Enab,

As you found out, in order to update the GridViewRowInfo you can call the InvalidateRow method. Another option is to call the Refresh method of the GridViewTemplate when you want to update all rows in the current view of the RadGridView control.

All the best,
Julian Benkov
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
mostafa
Top achievements
Rank 1
answered on 17 Oct 2016, 03:13 PM

Hi.

In my case just the selected rowwas changed!!!

0
Hristo
Telerik team
answered on 18 Oct 2016, 02:09 PM
Hello Mostafa,

Thank you for writing.

Can you please provide me with some details about your actual scenario and the version of the controls you are using? 

Looking forward to your reply.

Regards,
Hristo Merdjanov
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
0
mostafa
Top achievements
Rank 1
answered on 18 Oct 2016, 04:33 PM

Thanks for your reply,

BindingList Class solved my problem.

0
Michael
Top achievements
Rank 1
answered on 10 May 2017, 01:45 PM
Please provide example of using GridViewTemplate to refresh the RadGridView.  Thanks.
0
Hristo
Telerik team
answered on 11 May 2017, 03:03 PM
Hello Michael,

Thank you for writing back.

You can use the GridViewTemplate.Refresh method which will refresh the associated data view: 
this.radGridView1.MasterTemplate.Refresh();

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
jv
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
jv
Top achievements
Rank 1
Nick
Telerik team
Ehab
Top achievements
Rank 1
mostafa
Top achievements
Rank 1
Hristo
Telerik team
Michael
Top achievements
Rank 1
Share this question
or