none
Refreshing the datagrid

    General discussion

  • I have a basic SL example with several buttons (btn_Customers, btn_Products etc) and a single datagrid.

    Each button is similarly setup but only the first click results in data showing in the datagrid.

    The typical coding is as follows:

    'in MainPage.xaml.vb
    Private Sub svc_GetCustomersCompleted(sender As Object, e As SL_Enabled_WCFServiceReference.GetCustomersCompletedEventArgs) Handles svc.GetCustomersCompleted
    dg.ItemsSource = e.Result
    dg.Visibility = Windows.Visibility.Visible
    End Sub
    Private Sub btnLoad_Customers_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)

    svc.GetCustomersAsync()
    svc.CloseAsync()
    End Sub
    Private Sub btnLoad_Products_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)

    svc.GetProductsAsync()
    svc.CloseAsync()
    End Sub
    ***********************************
     ' part of code in the service
    
    
    <OperationContract()>
    Public Function GetCustomers() As List(Of Customer)
    Dim db As New NorthwindDataContext
    Return db.Customers.ToList()
    End Function
    etc.....
    ***********************************
    Question 1:
    How do I refresh the datagrid to allow any sequence of datapresentations rather than just the first choice clicked?
    
    
    Question 2:
    I'm using Linq to SQL and wondering what is syntax to get a customised list of data rather than all the data of the table?
    
    
    Sorry for such a long question(s).  Any help appreciated.
    
    
    Wednesday, October 19, 2011 7:10 AM

All replies

  • Hi,

    First, where is your svc_GetProductsCompleted?

    Second, you should set the ItemsSource to null and then set to the real result.

    dg.ItemsSource = Empty
    dg.ItemsSource = e.Result
    dg.Visibility = Windows.Visibility.Visible

    I'm using Linq to SQL and wondering what is syntax to get a customised list of data rather than all the data of the table?

    For this problem, I think you need to get start from this document:

    http://www.silverlight.net/learn/advanced-techniques/wcf-ria-services/get-started-with-wcf-ria-services

     

    Thursday, October 20, 2011 11:01 PM
  • Thanks Jerry.... svc_GetProductsCompleted exists (I didn't want to get too verbose).

    The idea of setting dg to null (dg.ItemsSource = Nothing) didn't change the behaviour of the datagrid.  Namely, once the datagrid gets populated that is it.  The next button click clears it but nothing new appears.  Any ideas?  Thanks

    <code>

     Private Sub svc_GetCategoriesCompleted(sender As Object, e As DataServiceReference.GetCategoriesCompletedEventArgs) Handles svc.GetCategoriesCompleted
    dg.ItemsSource = Nothing
    dg.ItemsSource = e.Result
    dg.Visibility = Windows.Visibility.Visible
    End Sub
    Private Sub svc_GetProductsCompleted(sender As Object, e As DataServiceReference.GetProductsCompletedEventArgs) Handles svc.GetProductsCompleted
    dg.ItemsSource = Nothing
    dg.ItemsSource = e.Result
    dg.Visibility = Windows.Visibility.Visible
    End Sub
    Private Sub btn_Product_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btn_Product.Click
    svc.GetProductsAsync()
    svc.CloseAsync()
    End Sub
    Private Sub btn_Category_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btn_Category.Click
    svc.GetCategoriesAsync()
    svc.CloseAsync()
    End Sub

    </code> 

    Friday, October 21, 2011 5:56 PM