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

[Solved] GridView Rebind Alternatives

9 Answers 258 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.
Timothy
Top achievements
Rank 1
Timothy asked on 16 Dec 2010, 07:42 AM
Are there any alternatives to updating the grid other than .Rebind()? The method below that I am using locks up the UI during the refresh every 10 seconds and doesnt seem like a smooth way to update the grid with backend data changes. The cell value does infact update automatically but I need the cell background color to change with it depending on a true or false value. This works fine when the grid loads and during a rebind but not automatically during a domain data source refresh.

I am using WCF RIA Services and am declaring the Domain Data Source as follows, Notice the use of RefreshInterval.

<riaControls:DomainDataSource AutoLoad="True"  x:Name="Event1DomainDataSource" RefreshInterval="00:00:10" QueryName="GetEvent1Query" d:IsHidden="True">
            <riaControls:DomainDataSource.DomainContext>
                <my:DomainService1 />
            </riaControls:DomainDataSource.DomainContext>
        </riaControls:DomainDataSource>


And in Code Behind I am calling rebind as follows, Notice the use of .IsBusy = False. I do this to avoid getting a Grid.Busy on screen every 10 seconds when the routine is called during Domain Data Source Refresh.

Private Sub Event1DomainDataSource_LoadingData(ByVal sender As Object, ByVal e As System.Windows.Controls.LoadingDataEventArgs) Handles Event1DomainDataSource.LoadingData
        e.LoadBehavior = MergeOption.PreserveChanges
        CheckListItemssDataGrid.Rebind()
        CheckListItemssDataGrid.IsBusy = False
    End Sub

My customcolumn is as below,

Imports System
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Ink
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports Telerik.Windows.Controls
Imports Telerik.Windows.Controls.GridView
Imports System.Windows.Controls.Primitives
  
  
Public Class CustomColumn
    Inherits GridViewDataColumn
  
    Public Overrides Function CreateCellElement(ByVal cell As GridViewCell, ByVal dataItem As Object) As FrameworkElement
        cell.SetBinding(GridViewCell.ValueProperty, Me.DataMemberBinding)   
        If cell.Value = "True" Then
            cell.Background = New SolidColorBrush(Colors.Green)
        ElseIf cell.Value Is Nothing Then
            cell.Background = New SolidColorBrush(Colors.LightGray)
        End If
    End Function
End Class


Please help.

9 Answers, 1 is accepted

Sort by
0
Timothy
Top achievements
Rank 1
answered on 16 Dec 2010, 07:47 AM
Nothing
0
Timothy
Top achievements
Rank 1
answered on 16 Dec 2010, 08:55 AM
How can I update the cell background color without a rebind when the underlying cell value changes?


Please, please help me.!


Thank you,
Tim
0
Vlad
Telerik team
answered on 16 Dec 2010, 08:59 AM
Hi,

You can use CellStyleSelector to achieve your goal. SelectStyle() method will be triggered automatically after property value change of INotifyPropertyChanged object.

Kind regards,
Vlad
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Timothy
Top achievements
Rank 1
answered on 16 Dec 2010, 09:11 AM
Is this the only way. Is there any way to reapply cell background color without a Style Selector?
0
Vlad
Telerik team
answered on 16 Dec 2010, 09:22 AM
Hi,

 The old approach is Binding for desired property with IValueConverter. Bindings will be re-executed as well on property value change of INotifyPropertyChanged object.

Best wishes,
Vlad
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Timothy
Top achievements
Rank 1
answered on 16 Dec 2010, 10:02 AM
I am using a Domain Data Source without MVVM.

I applied the style selector and it works with one caveat.

It only works if I set a refresh interval on my Domain Data Source. Without a refresh interval the cell vlaue never changes and thus the style never gets applied.

Should my cell value change automatically when the backend SQL data changes. Or is setting a refresh rate on the domain data source my only option?
0
Vlad
Telerik team
answered on 16 Dec 2010, 10:23 AM
Hello,

 The DomainDataSource will not re-download the data automatically if something is changed on the server. 

Kind regards,
Vlad
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Timothy
Top achievements
Rank 1
answered on 16 Dec 2010, 10:29 AM
So setting the refresh rate is my only option right?
0
Vlad
Telerik team
answered on 16 Dec 2010, 10:31 AM
Hi,

 Indeed this is the only option I can think of. 

Regards,
Vlad
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
GridView
Asked by
Timothy
Top achievements
Rank 1
Answers by
Timothy
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or