Welcome to the Xceed Community | Help
Community Search  
More Search Options

Refresh DataGrid After Database Update

Sort Posts: Previous Next
  •  12-22-2008, 12:21 PM Post no. 17605

    Refresh DataGrid After Database Update

    Hello guys!

    i'm have a DataGridCollectionViewSource with the follow code:
    <xcdg:DataGridCollectionViewSource x:Key="SetorSelecao"

                                                   Source="{Binding RelativeSource={RelativeSource AncestorType={x:Type me:Setor_Grid}},

                                                   Path=Selecao}" AutoFilterMode="And">

                    <xcdg:DataGridCollectionViewSource.ItemProperties>                   

                        <xcdg:DataGridItemProperty Name="IdSetor"

                                                   Title="IdSetor"

                                                   CalculateDistinctValues="False"/>                   

                        <xcdg:DataGridItemProperty Name="Setor"

                                                   Title="Setor"/>                   

                        <xcdg:DataGridItemProperty Name="Situacao"

                                                   Title="Situação"/>               

                    </xcdg:DataGridCollectionViewSource.ItemProperties>

     </xcdg:DataGridCollectionViewSource>

     

    And a DataGrid with the follow:
    <xcdg:DataGridControl Name="dgSetor"

                          ItemsSource="{Binding Source={StaticResource SetorSelecao}}"

                          ReadOnly="True" EditTriggers="None" SelectionMode="Single" NavigationBehavior="RowOrCell" 
                          MouseDoubleClick
    ="dgSetor_MouseDoubleClick">

    </xcdg:DataGridControl>

    When i click two times in Grid, its calls another window where i edit the register.
    But after the edition, the grid still the same. The rows are not affected.
    I tried this, like in samples:

                ((DataGridCollectionView)this.dgSetor.ItemsSource).Refresh();

    But doesn’t work.
    Someone can help me!?

    Thanks a lot!


  •  12-22-2008, 3:12 PM Post no. 17609 in reply to 17605

    Re: Refresh DataGrid After Database Update

    Hi Daniel, 

      what is the type of your "me:Setor_Grid" source? 


    Christian Nadeau
    Software Developer
    Xceed Software Inc.
  •  12-22-2008, 5:28 PM Post no. 17612 in reply to 17609

    Re: Refresh DataGrid After Database Update

    Hi Cristian!

    Source="{Binding RelativeSource={RelativeSource AncestorType={x:Type me:Setor_Grid}},Path=Selecao}"

    Where “me:” is my namespace and “Setor_Gird” is my Window, from where i catch the property "Selecao":

    public partial class Setor_Grid : Window
    {
       private
    IEnumerable selecao = null; 
       public
    IEnumerable Selecao
       {
          get
          {
             if (selecao == null)
             {
                 selecao =
    Setor.Pesquisar();
             }
             return selecao;
         }
    //.......

    AndSetor.Pesquisar()” returns a IQueryable From a Linq.
    At the first time, or when i close and open the window, its works ok. But after update the database with another window, the rows don’t change.

    Any ideas!?

    Thanks so much!!

     

  •  12-23-2008, 9:05 AM Post no. 17621 in reply to 17612

    Re: Refresh DataGrid After Database Update

    Hi,

      The problem comes from your "Selecao" data source: it won't send any notifications to the DataGridCollectionView that it has changed since an IQueryable must be "queried" to provide data.

     To get your data refreshed, you should define IEnumerable Selecao as a DependencyProperty and reaffect its value with Setor.Pesquisar() when you know the other Window modified the underlying data source. This will trigger a notification that the Selecao property has changed and the binding of the DataGridCollectionViewsource must be refreshed.


    Christian Nadeau
    Software Developer
    Xceed Software Inc.
  •  02-01-2009, 7:55 AM Post no. 18322 in reply to 17621

    Re: Refresh DataGrid After Database Update

    Hi,

    How do you go about using a Dependency Property when you bind to Linq to SQL Classes?  They inherit from System.Data.Linq.Data.Context which does not provide the SetValue method (inherited from DependencyObject).  As far as I can figure out, it is this member that triggers the change notification.

    I don't see why there can't just be a Refresh method?  It would make life soooo much easier.  I'm new to this stuff, so there may be a valid reason.

    Thanks,
    Craig

  •  04-21-2009, 10:51 AM Post no. 20427 in reply to 17621

    Re: Refresh DataGrid After Database Update

    I am trying to achieve the same here.  Chris, please could you elaborate on how to do this?  I too have a DataGridControl bound using the following XAML:

    <xcdg:DataGridCollectionViewSource x:Key="xmlData" Source="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=XmlData}" />

    Then I have XmlData defined as thus:

    public IEnumerable XmlData

    {

        get

        {

            var data = from order in _myDoc.Element("ROOT").Descendants("CHILDREN")

                select new

                {

                    Element1 = order.Element("ELEMENT1").Value,

                    Element2 = order.Element("ELEMENT2").Value,

                };

            return data.ToList();

        }

        set

        {

            SetValue(XmlDataProperty, value);

        }

    }

     

    public static readonly DependencyProperty XmlDataProperty =

        DependencyProperty.Register(

        "XmlData",

        typeof(IEnumerable),

        typeof(DataGridControl),

        new PropertyMetadata(null, OnXmlDataPropertyChanged));

     

    private static void OnXmlDataPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

    {

        int x = 0;

    }

     

    All I want to be able to do is get the DataGridControl to update when _myDoc changes by programmatically or automatically invoking some sort of refresh.


    Associate, .NET Development
    Morgan Stanley, UK
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.