Select to view content in your preferred language

Blank Datagrid

890
4
06-03-2011 01:16 PM
AgatinoLa_Rosa
Emerging Contributor
I have a simple query on a web service and the result should populate a datagrid. However I get a blank datagrid and I may have done something wrong. Any help?

At design time:
<sdk:DataGrid  Name="grdCity" AutoGenerateColumns="False" HorizontalAlignment="Left" HeadersVisibility="All" CanUserResizeColumns="False" CanUserReorderColumns="False">              
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="City" Width="400" Binding="{Binding Attributes[NAME]}" />
<sdk:DataGridTextColumn Header="2010 Population" Width="220" Binding="{Binding Attributes[Pop_2010]}"  />
</sdk:DataGrid.Columns>
</sdk:DataGrid>



At runtime:

        {
            InitializeComponent();
            QueryTask qryCity = new QueryTask("http://myserver/rest/services/.../MapServer/0");
            qryCity.ExecuteCompleted += qryCity_ExecuteCompleted;
            qryCity.Failed += qryCity_Failed;
            Query allCitiesQuery = new Query();
            allCitiesQuery.OutFields.AddRange(new string[] { "NAME", "Pop_2010" });
            allCitiesQuery.ReturnGeometry = false;
            allCitiesQuery.Where = "State='myState'";
            qryCity.ExecuteAsync(allCitiesQuery);
        }
void qryCity_ExecuteCompleted(object sender, QueryEventArgs args)
        {
            FeatureSet fsetCity = args.FeatureSet;
            myDatagrid.ItemsSource = args.FeatureSet.Features;
        }

0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
At first glance your code looks good.
The only strange thing is that your datagrid is called 'grdCity' in XAML and 'myDataGrid' in C#.   Is it supposed to be the same thing?
0 Kudos
AgatinoLa_Rosa
Emerging Contributor
I found that I had the datagrid inside a scrollviewer object that caused the problem. Now is working. thanks. the mydatagrid.itemssource was my mistyping on the post

One more question. Is there any example I can see so I can pass an object with my query features to another page of my SL navigation application? i.e. I have the features queried in PageA and the DataGrid in PageB. I have used the DataContext property on PageA however PageB receives an empty object. Thanks
0 Kudos
DominiqueBroux
Esri Frequent Contributor
If your pageB contains only the datagrid, you can use the DataContext of the PageB to store the list of graphics.

In your C# code : set the datacontext of your pageB:
    pageB.DataContext = = args.FeatureSet.Features;

In XAML, bind the itemssource of your datagrid to the datacontext itself, i.e. <controls:DataGrid ItemsSource='{Binding}' ....
0 Kudos
AgatinoLa_Rosa
Emerging Contributor
It is not working. Perhaps I am not sure how to initialize PageB into PageA.
in the declaration section of my PageA I have:

private PageB _mypageB = new PageB();

in my "qryCity_ExecuteCompleted" (in PageA) I have:

_mypageB.DataContext = args.FeatureSet;

In my PageB I have:

if (this.DataContext == null) {return;};

and it stops there, so PageB.DataContext is null.

Is this correct?

Thanks
0 Kudos