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

Updating Gridview programmatically

8 Answers 312 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Monika Kogler
Top achievements
Rank 1
Monika Kogler asked on 29 Jun 2010, 03:01 PM
Hi,
i need to update my gridview programmatically but nothing i have tried is working. thats my scenario:
i have a grid with several different columns (combobox-, textbox-, checkbox-column), some of them can be edited, some of them are calculated and can't be edited by user. one row is representing one object, the grid is bound via itemsource.
the following process has to be implemented now:
1. user changes the value of an editable field
2. cell_validating-event is fired
3. in the cell_validating-event, the input is first verified. if the inserted value is okay, 3 other values are generated (bound to 3 non-editable columns)
4. after assigning the new values the grid needs to be updated (generated values should show up).

everything is working till step 4. i have tried to assign a new itemsource and call rebind, i have checked on the bindings, but nothing is working. if i load the page containing the grid a second time my data is showing up, but it need to be there directly after the validation! any suggestions?

8 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 29 Jun 2010, 03:06 PM
Hello Monika Kogler,

 Do your data items implement INotifyPropertyChanged?

Regards,
Yavor Georgiev
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
Monika Kogler
Top achievements
Rank 1
answered on 29 Jun 2010, 03:12 PM
Hi,
No it doesn't, but I like to avoid the INotifyPropertyChanged interface. Is there any other thing i can do?
Thx in advance
0
Yavor Georgiev
Telerik team
answered on 29 Jun 2010, 03:18 PM
Hi Monika Kogler,

 The INotifyPropertyChanged interface is the corner-stone of effortless data binding in the WPF and Silverlight worlds. I strongly recommend that you revise your opinion of it.

Could you please try call Rebind() only, without touching the ItemsSource. Do please note that calling Rebind() every time a cell is changed is a performance hit.

I still strongly advocate using INotifyPropertyChanged.

All the best,
Yavor Georgiev
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
Monika Kogler
Top achievements
Rank 1
answered on 29 Jun 2010, 03:21 PM
calling rebind doen't make any changes - the grid is not updated. that's accually one of the things i thought it could work out. any other suggestions?
0
Yavor Georgiev
Telerik team
answered on 29 Jun 2010, 03:23 PM
Hello Monika Kogler,

 It would help us immensely in tracking down the issue if you'd open a support ticket and attach a small sample application that reproduces this issue. I would be very grateful if you do so.

Sincerely yours,
Yavor Georgiev
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
Monika Kogler
Top achievements
Rank 1
answered on 29 Jun 2010, 04:18 PM
hi,
i have added my sample to a bug report. hope that helps solving this problem because i really need a solution for this until the end of this week. please let me know if you have any futher suggestions.
0
ManniAT
Top achievements
Rank 2
answered on 06 Aug 2010, 12:12 AM
Any solution on this?

I have the same problem (Rebind not working).

To explain the things - I work with Linq2Sql - which is (unfortunately)  not fully supported by RadGrid.
So I have to do a lot in code behind.
Anyhow - I found a nice support sample so this was not to hard - from the first point of view.

About the problem:
In the RowEditEnded I take care about inserts like this:
Snippet created with CBEnhancer
ImportDirectory iD = e.EditedItem as ImportDirectory;
if(e.EditOperationType == GridViewEditOperationType.Insert) {
    m_dC.ImportDirectories.InsertOnSubmit(iD);
    m_dC.SubmitChanges();
    rgvDirectories.Rebind();
This doesn't show the inserted row.
So I changed to this (from the support code):
Snippet created with CBEnhancer
m_dC.ImportDirectories.InsertOnSubmit(iD);
m_dC.SubmitChanges();
m_dC.Refresh(System.Data.Linq.RefreshMode.KeepChanges, m_dC.ImportDirectories);
rgvDirectories.Rebind();
This doesn't show the newly added row.
So I solve it "brute force":
Snippet created with CBEnhancer
m_dC.ImportDirectories.InsertOnSubmit(iD);
m_dC.SubmitChanges();
rgvDirectories.ItemsSource = null;
//m_dC.Refresh(System.Data.Linq.RefreshMode.KeepChanges, m_dC.ImportDirectories);
rgvDirectories.ItemsSource = m_dC.ImportDirectories;
As you may have noticed - I didn't call the (time consuming refresh).
Instead I "undbind" the Grid - which shows some (handled) "Argument Exceptions" in debug.
And bind it again - that works!

A final interesting thing - for delete Rebind works:
Snippet created with CBEnhancer
m_dC.ImportDirectories.DeleteOnSubmit(iD);
m_dC.SubmitChanges();
//rgvDirectories.ItemsSource = null;
//m_dC.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, m_dC.ImportDirectories);
//rgvDirectories.ItemsSource = m_dC.ImportDirectories;
rgvDirectories.Rebind();

I know that Linq2Sql is missing Observable.... - but I thought Grid.Rebind() should overcome this problem.
But it does the job only partial (in delete) - for insert only "brute force" works.

That's why I aske here since Monika seems to have a similar problem.
My hope is that here support ticket resulted in a solution.

Manfred
0
Vlad
Telerik team
answered on 11 Aug 2010, 09:48 AM
Hello,

Why not use a bit more different approach - for example MVVM. I've made for you small example application to illustrate you how to achieve your goal with LINQ to SQL - you can find the project attached. In the previous case rebind didn't worked since it was called during Validating event which is not correct.

All the best,
Vlad
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
Tags
GridView
Asked by
Monika Kogler
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Monika Kogler
Top achievements
Rank 1
ManniAT
Top achievements
Rank 2
Vlad
Telerik team
Share this question
or