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

[Solved] GridView is not refreshed

3 Answers 199 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
xp
Top achievements
Rank 1
xp asked on 28 Jul 2009, 06:00 PM
we have one gridview and one textbox. when user select one row in gridview, the textbox'Text is bind to  content of one cell in selected row.
If Textbox 's Text changed, we can see the CurrentItem and ItemsSource changed, but gridView UI is not refreshed.  How to refresh it?

If I call gridview.Rebind(), the gridview UI will refresh, but selection and currentitem are gone. if there are a lot of row in gridview, rebind will take a long time.

Thanks

3 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 29 Jul 2009, 02:32 PM
Hello sam,

I am not sure if I got your question correctly so I would like to ask you for some clarifications. When the TextBox's text changes what data do you expect to change - is it the cell value that the TextBox is bound to?

All the best,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
xp
Top achievements
Rank 1
answered on 29 Jul 2009, 03:31 PM
Hi Milan,

Here is my xaml:

...
  <telerikGrid:RadGridView Name="MyDataGrid" IsReadOnly="True"  AutoGenerateColumns="False" >
                <telerikGrid:RadGridView.Columns>
                    <telerikGrid:GridViewDataColumn HeaderText="Description" DataMemberPath="ValidationTypeDesc"/>
                <telerikGrid:RadGridView.Columns>
</telerikGrid:RadGridView>

...
                        <TextBox x:Name="txtMyDesc" Text="{Binding ElementName=MyDataGrid, Path=CurrentItem.MyDesc, Mode=TwoWay}" />

..
Codes behind:
  MyDataGrid.ItemsSource = myCollection;
  //myCollection is a ObservableCollection
....

When user select different row in DataGrid, the TextBox will display different MyDesc accordly without problem. However, when user change Textbox's Text, DataGrid's UI is not refreshed. In debug mode, I check the ItemsSource did change after user change TextBox's Text.

Do I need to set GridView's ItemsSource to a twoway binding? something like this:
            Binding b = new Binding();
            b.Mode = BindingMode.TwoWay;
            b.Source = myCollection;
            b.Path = ...;//Problem is here, how to set path to a ObservableCollection?
            MyDataGrid.SetBinding(Telerik.Windows.Controls.RadGridView.ItemsSourceProperty, b);

..

Thanks
0
Milan
Telerik team
answered on 03 Aug 2009, 02:59 PM
Hello sam,

The grid is not updated because there is no way to detect that the MyDesc property of a particular object has changed. In order to support such scenarios your data objects should implement the INotifyPropertyChanged interface and raise PropertyChange events whenever a property value changes.

Here you can find more information about the INotifyPropertychanged interface - http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged(VS.95).aspx

Here is a sample implementation:

public class Person : INotifyPropertyChanged  
{  
    public event PropertyChangedEventHandler PropertyChanged;  
    private string Fname;  
 
    public string FName  
    {  
        get 
        {  
            return this.Fname;  
        }  
        set 
        {  
            this.Fname = value;  
            this.OnPropertyChanged("FName");  
        }  
    }  
 
    protected virtual void OnPropertyChanged(string propertyName)  
    {  
        if (this.PropertyChanged != null)  
        {  
            this.PropertyChanged(thisnew PropertyChangedEventArgs(propertyName));  
        }  
    }  


Greetings,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
xp
Top achievements
Rank 1
Answers by
Milan
Telerik team
xp
Top achievements
Rank 1
Share this question
or