Solved! Go to Solution.
void QueryTask_ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e)
{
IEnumerable<Graphic> graphics = e.Result.RelatedRecordsGroup.First().Value;
RelationshipResult pr = e.Result;
if (pr.RelatedRecordsGroup.Count == 0)
{
RelatedRowsDataGrid.ItemsSource = null;
}
else
{
foreach (var pair in pr.RelatedRecordsGroup)
{
RelatedRowsDataGrid.ItemsSource = pair.Value;
MyFDG.ItemsSource = pair.Value;
}
}
}
foreach ( var pair in pr.RelatedRecordsGroup )
{
MyFDG.ItemsSource = pair.Value.Select(g => g.Attributes);
}
private void QueryTask_ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e) { IEnumerable<Graphic> graphics = e.Result.RelatedRecordsGroup.First().Value; RelationshipResult pr = e.Result; if (pr.RelatedRecordsGroup.Count == 0) { RelatedRowsDataGrid.ItemsSource = null; } else { foreach (var pair in pr.RelatedRecordsGroup) { RelatedRowsDataGrid.ItemsSource = pair.Value; MyFDG.ItemsSource = pair.Value; } } } private void QueryTask_ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e) { //This line gets you the all features returned from the Relationship Query IEnumerable<Graphic> graphics = e.Result.RelatedRecordsGroup.First().Value; // There are two ways to filter either using Where clause or using the ObjectIDs property // before you set the Where clause to return all records 1=1 I think // Here instead lets use the ObjectIDs approach, first get rid of the old Where _featureLayer.Where = null //remember _featureLayer is l //ObjectIDs takes an int[] and with a little Linq we can get that array // I am assumning you have included OBJECTID in your outfields when you defined the query int[] objectIds = graphics.Select(g => (int)g.Attributes["OBJECTID"]).ToArray(); //now set the ObjectIDs on our FeatureLayer _featureLayer.ObjectIDs = objectIds; //Update the FeatureLayer to 'redraw' the new filtered set of Features _featureLayer.Update(); //And I hope this worked. you could rebind the layer to the grid to make sure all is good MyFDG.GraphicsLayer = _featureLayer; }
<!-- RELATED LINK RESOURCE-->
<common:HierarchicalDataTemplate x:Key="TreeViewItemTemplate">
<StackPanel Orientation="Horizontal" Margin="0">
<!--<Ellipse Fill="Transparent" Height="6" Width="6" StrokeThickness="2" Stroke="Black" Margin="0,0,10,0"/>-->
<!--<TextBlock Text="FeatureID: " HorizontalAlignment="Left" FontSize="10" Margin="0"/>-->
<TextBlock x:Name="TextBlockRelate" Text="{Binding Attributes[APN]}" HorizontalAlignment="Left" FontSize="10"/>
</StackPanel>
</common:HierarchicalDataTemplate>
<!--END RELATED LINK RESOURCE-->
<basics:TreeView x:Name="SelectedWellsTreeView" MaxHeight="180" Grid.Column="0" Margin="1"
ItemsSource="{Binding}" BorderBrush="Gray" BorderThickness=".5"
SelectedItemChanged="SelectedWellsTreeView_SelectedItemChanged"
ItemTemplate="{StaticResource TreeViewItemTemplate}"
/>
private void addrowButton_Click(object sender, RoutedEventArgs e)
{
var g = new Graphic();
if (l != null && l.LayerInfo != null && l.LayerInfo.Fields != null)
{
foreach (var f in l.LayerInfo.Fields)
{
g.Attributes[f.Name] = null;
// g.Attributes["APN"] = RelateIdTextBlock.Text;
// g.Attributes["APN"] = SelectedWellsTreeView.SelectedValue.ToString());
}
}
else
{
//g.Attributes["sf_311_serviceoid"] = 21467;
//g.Attributes["agree_with_incident"] = (Int16)1;
//g.Attributes["DateTime"] = DateTime.UtcNow;
//g.Attributes["cient_ip"] = "unknown";
//g.Attributes["notes"] = string.Format("Added - {0} - local time", DateTime.Now);
// g.Attributes["APN"] = 2146700000;
//g.Attributes["GEN_PLAN"] = "GPk";
}
l.Graphics.Add(g);
}
//The OID of the current related feature that the user selected
private int _currentLocationId;
private void SpatialQueryCompleted(object sender, QueryEventArgs e)
{
if ( e.FeatureSet.Features.Count() == 0 ) return;
Graphic graphic = e.FeatureSet.Features[0];
//Assign the location OID to internal field so can use when a new record is created
_currentLocationId = Convert.ToInt32(graphic.Attributes["OBJECTID"]);
RelationshipParameter parameter = new RelationshipParameter
{
ObjectIds = new[] { _currentLocationId },
RelationshipId = 0,
OutFields = new[] { "OBJECTID" }
};
_queryTask.ExecuteRelationshipQueryCompleted += RelationshipQueryCompleted;
_queryTask.ExecuteRelationshipQueryAsync(parameter);
}
private void ExecuteAdd()
{
//Create the new Graphic object and set the default values for the attributes
Graphic graphic = new Graphic();
...
graphic.Attributes.Add("LOCATION_OID", _currentLocationId);
_featureLayer.Graphics.Add(graphic);
//Set the bound GraphicsSource so the DataForm is loaded with the new record
GraphicSource = graphic;
}
private void DeleteButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
_featureLayer.Graphics.Remove(MyFeatureDataGrid.SelectedGraphics[0]);
}