Select to view content in your preferred language

FeatureDataGrid Binding

970
6
12-14-2011 12:29 AM
DidarBultanov
Emerging Contributor
Hi all, I want to filter the datagrid to do this in the header of the grid I made â??â??a combobox how to bind a value to the combobox field?
<esri:FeatureDataGrid x:Name="MyFeatureDataGrid" Map="{Binding ElementName=MyMap}" IsReadOnly="True" >
<esri:FeatureDataGrid.ColumnHeaderStyle>
<Style TargetType="sdk:DataGridColumnHeader" >
<Setter Property="FontSize" Value="10" />
<Setter Property="ContentTemplate" >
<Setter.Value>
<DataTemplate >
<StackPanel>
<ComboBox ItemsSource="{Binding value}"/>
<TextBlock Text="{Binding}"/>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</esri:FeatureDataGrid.ColumnHeaderStyle>
</esri:FeatureDataGrid>
Default return all data
var featureLayer = new FeatureLayer();
featureLayer.Mode = FeatureLayer.QueryMode.Snapshot;
featureLayer.Where = "1=1";
featureLayer.AutoSave = false;
featureLayer.OutFields.Add("*");
featureLayer.DisableClientCaching = true;
featureLayer.Initialized += featureLayer_Initialized;
featureLayer.Url = MyFeatureService + "/" + NumServices;
featureLayer.Initialize();
MyFeatureDataGrid.GraphicsLayer = featureLayer;
0 Kudos
6 Replies
JenniferNery
Esri Regular Contributor
Have you looked at this sample? http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolkitFeatureDataGrid

I'm not sure I understand your code-snippet. You are using ComboBox to filter what? graphic attributes? In this case, you can use FeatureDataGrid.FilterSource property.

Or is FeatureDataGrid.GraphicsLayer property determined at run-time? This might be related thread: http://forums.arcgis.com/threads/35568-Binding-Query-Result-To-FeatureDataGrid
0 Kudos
DidarBultanov
Emerging Contributor
Have you looked at this sample? http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolkitFeatureDataGrid

I'm not sure I understand your code-snippet. You are using ComboBox to filter what? graphic attributes? In this case, you can use FeatureDataGrid.FilterSource property.

Or is FeatureDataGrid.GraphicsLayer property determined at run-time? This might be related thread: http://forums.arcgis.com/threads/35568-Binding-Query-Result-To-FeatureDataGrid

I want to make the user to select the desired item in the combo box for filtering.(how to excel) Then I will do so:
FeatureDataGrid.FilterSource ="columnname=data" (data=combobox.text)
<ComboBox ItemsSource="{Binding value}"/> as bind a combo box to display data from a column?
screens: http://fotoifolder.ru/view_foto/x0_bnaf3zueo/
0 Kudos
DidarBultanov
Emerging Contributor
Up up up 🙂
0 Kudos
JenniferNery
Esri Regular Contributor
You can modify the following SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolkitFeatureDataGrid

If your ComboBox contains the query string, you can translate this to Linq query and set FeatureDataGrid.FilterSource property.

Add in the XAML:
<ComboBox x:Name="Filter" SelectionChanged="Filter_SelectionChanged" VerticalAlignment="Top" HorizontalAlignment="Center">
   <ComboBox.ItemTemplate>
    <DataTemplate>
     <TextBlock Text="{Binding}"/>
    </DataTemplate>
   </ComboBox.ItemTemplate>
  </ComboBox>


Add in Code-behind ( be sure you have using System.Linq; 😞
//After InitializeComponent
   Filter.ItemsSource = new string[]
   {
    "1 = 1",
    "status = 1", 
    "req_type = 'Graffiti Complaint - Public Property'",
    "status = 1 and req_type = 'Graffiti Complaint - Public Property'"
   };


private void Filter_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {
   var query = Filter.SelectedItem as string;
   var l = MyMap.Layers["IncidentsLayer"] as FeatureLayer;
   if(query == "1 = 1")
    MyDataGrid.FilterSource = null;
   else if (query == "status = 1")
   {
    MyDataGrid.FilterSource = (from g in l.Graphics
             where (Int16)g.Attributes["status"] == 1
             select g).ToList();
   }
   else if (query == "req_type = 'Graffiti Complaint - Public Property'")
   {
    MyDataGrid.FilterSource = (from g in l.Graphics
             where (string)g.Attributes["req_type"] == "Graffiti Complaint - Public Property" 
             select g).ToList();
   }
   else if (query == "status = 1 and req_type = 'Graffiti Complaint - Public Property'")
   {
    MyDataGrid.FilterSource = (from g in l.Graphics
             where (Int16)g.Attributes["status"] == 1 && (string)g.Attributes["req_type"] == "Graffiti Complaint - Public Property"
             select g).ToList();
   }
  }
0 Kudos
DidarBultanov
Emerging Contributor

Add in the XAML: 
<ComboBox x:Name="Filter" SelectionChanged="Filter_SelectionChanged" VerticalAlignment="Top" HorizontalAlignment="Center">
   <ComboBox.ItemTemplate>
    <DataTemplate>
     <TextBlock Text="{Binding}"/>
    </DataTemplate>
   </ComboBox.ItemTemplate>
  </ComboBox>



Thank you, understand the idea, but I need to fill combobox with the value from the current field
<DataTemplate>
<TextBlock Text= data form current field
</DataTemplate>
Is it possible?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
From my understanding, your problem is no more related to the feature datagrid.
You just need to populate a combo box with all distinct values of a specific field.

To do that you need to initialize correctly the ItemsSource property of your combo box.
Something like:
Filter.ItemsSource = l.Graphics.Select(g => g.Attributes["MyField"].ToString()).Distinct();
0 Kudos