Datagrid failing to update after DomainClient.BeginQuery RRS feed

  • General discussion

  • Hello fellow programmers,

     I am trying to dynamically load query results from a DomainClient into a datagrid. So far, the query works and results in an entitylist with the corresponding entities.

     Please consider my code:

            private void sourceList_SelectionChanged(object sender, SelectionChangedEventArgs e)
                lastSet = sourceList.SelectedItem.ToString();
                string methodName = "Get" + lastSet.TrimEnd('s');
                var type = Assembly.GetExecutingAssembly().GetType("PMF.Web.Data." + lastSet.TrimEnd('s'));
                context.DomainClient.BeginQuery(methodName, null, null, false, new AsyncCallback(QueryLoaded), lastSet);

            public void QueryLoaded(IAsyncResult result)
                if (result.IsCompleted)
                    var results = context.DomainClient.EndQuery(result);

                    var val1 = results.Entities.ToList();

                        dataGrid.ItemsSource = null;
                        dataGrid.ItemsSource = val1; // <-- val1 has entities, but the datagrid isn't updated with the new information

     So, there is a result from the query. I have to use the Dispatcher.BeginInvoke to prevent cross-thread issues. The datagrid doesn't update, I have autogeneratecolumns set to true. I guess it is somekind of threading issue.

     Do you guys have any idea ?

    Monday, September 7, 2009 5:28 AM

All replies

  • Have you tried turning autogeneratecolumns off and back on in the delegate?

    Tuesday, September 8, 2009 2:56 AM
  • Yes I have, that doesn't seem to change anything.

    Is there any logic behind setting the autogeneratecolumns to true and false for this issue?

    Tuesday, September 8, 2009 6:53 AM
  • This issue has not been resolved yet. Is there anyone who has any idea ?

    Wednesday, October 14, 2009 9:54 AM
  • Does it work without using the Dispatcher? e.g.

    dataGrid.ItemsSource = null;

    dataGrid.ItemsSource = val1;

    Wednesday, October 14, 2009 10:09 AM
  • Is there a reason you are bypassing the DomainContext and going directly to the DomainClient? I haven't seen anybody try this before and I am curious what your reasoning was.

    Wednesday, October 14, 2009 10:47 AM