ObjectID not visible in FeatureDataGrid

927
7
Jump to solution
01-09-2013 07:24 AM
jonathangamble
New Contributor III
Hi,

Just wondering why my ObjectID field would not be visible in my FeatureDataGrid?

My featurelayer.outfields is set to "*".

If I look through my graphics contained in my graphics layer, I can see the 'OBJECTID' field within the attribute list.

However, if I create an event on AutoGeneratingColumn and printout all of the attributes, the OBJECTID is never listed.

Any ideas on why my OBJECTID field is not being picked up?


Thanks
0 Kudos
1 Solution

Accepted Solutions
ChrisTallman
New Contributor III
You can go ahead and leave the "*" in place on your layer. The OBJECTID field is ignored if you let the data grid AutoGenerate the Columns.  If you want to continue to see all the fields plus the OBJECTID field leave AutoGenerateColumns = True and add the OBJECTID manually.  Or you can add all the fields you would like to see and turn off the AutoGenerateColumns.  Here is the code to be able to do that.

Add the following to the top:
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 


And Edit your FeatureDataGrid as follows:

<esri:FeatureDataGrid Grid.Row="3" Grid.ColumnSpan="3" x:Name="MyDataGrid"   Map="{Binding ElementName=MyMap}" MaxHeight="400" AutoGenerateColumns="True"    GraphicsLayer="{Binding Layers.[MyFeatureLayer], ElementName=MyMap}" >      <esri:FeatureDataGrid.Columns>           <sdk:DataGridTextColumn Binding="{Binding OBJECTID}" Width="Auto" Header="Object ID"/>      </esri:FeatureDataGrid.Columns> </esri:FeatureDataGrid>


If you want to add other fields just continue to add:
<sdk:DataGridTextColumn Binding="{Binding OBJECTID}" Width="Auto" Header="Object ID"/>


Binding to the field from your data source.  You can add other field types to your datagrid in this same manner.  You can add a DataGridCheckBoxColumn and a DataGridTemplateColumn.

Hope this helps.

Chris

View solution in original post

0 Kudos
7 Replies
ChrisTallman
New Contributor III
Looks like its build in the toolkit to not show the ObjectId field if the "*" is used.  I see this line of code in the toolkit source code.

// Don't show object id field.
if (featureLayer.LayerInfo.ObjectIdField == mappedKey)
{
 e.Cancel = true;
 return;
}


If you want the ObjectId to show specifically add the fields to your OutFields List.

Chris
0 Kudos
jonathangamble
New Contributor III
Chris - Interesting find ...

I've tried setting my outFields to be 'OBJECTID' and it is still filtered out. 

Any idea how the 'mappedKey' variable is determined within that statement?
0 Kudos
jonathangamble
New Contributor III
Update: does anyone know how I can manually add this column (objectID) back into the featuredatagrid?

It's pretty frustrating that Esri has decided to hide this field by default.
0 Kudos
ChrisTallman
New Contributor III
You can go ahead and leave the "*" in place on your layer. The OBJECTID field is ignored if you let the data grid AutoGenerate the Columns.  If you want to continue to see all the fields plus the OBJECTID field leave AutoGenerateColumns = True and add the OBJECTID manually.  Or you can add all the fields you would like to see and turn off the AutoGenerateColumns.  Here is the code to be able to do that.

Add the following to the top:
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 


And Edit your FeatureDataGrid as follows:

<esri:FeatureDataGrid Grid.Row="3" Grid.ColumnSpan="3" x:Name="MyDataGrid"   Map="{Binding ElementName=MyMap}" MaxHeight="400" AutoGenerateColumns="True"    GraphicsLayer="{Binding Layers.[MyFeatureLayer], ElementName=MyMap}" >      <esri:FeatureDataGrid.Columns>           <sdk:DataGridTextColumn Binding="{Binding OBJECTID}" Width="Auto" Header="Object ID"/>      </esri:FeatureDataGrid.Columns> </esri:FeatureDataGrid>


If you want to add other fields just continue to add:
<sdk:DataGridTextColumn Binding="{Binding OBJECTID}" Width="Auto" Header="Object ID"/>


Binding to the field from your data source.  You can add other field types to your datagrid in this same manner.  You can add a DataGridCheckBoxColumn and a DataGridTemplateColumn.

Hope this helps.

Chris
0 Kudos
jonathangamble
New Contributor III
Hey Chris,

Thanks!  This worked for me.

One follow up question for you - I have a dropdown box within my application where I select the layer I want to display in my featuredatagrid.  Because each layer might have a different ObjectID field name, I am dynamically binding the column once a change in the combo selection has occurred (See code below) ... is there anyway I could accomplish this type of binding within XAML?

// Clear the columns
fdgAttributes.Columns.Clear();

// Add the new objectID field
ESRI.ArcGIS.Client.FeatureLayer fl = _vm.SelectedLayer;
                
DataGridTextColumn col = new DataGridTextColumn();
col.Header = fl.LayerInfo.ObjectIdField;
col.Binding = new System.Windows.Data.Binding(fl.LayerInfo.ObjectIdField);
fdgAttributes.Columns.Add(col);

 // Set my featuredatagrid graphics layer
 fdgAttributes.GraphicsLayer = _vm.SelectedLayer as GraphicsLayer;
0 Kudos
ChrisTallman
New Contributor III
I think the way you are doing it is probably the best solution. 

I took a look at the code for the featuredatagrid to see about adding a property to allow the user to show/hide the objectid by a setting in xaml.  I found something interesting it doesnt seem like the objectid ever makes it to the Column AutoGeneration. 

Im not sure if this is on purpose it would be interesting to have someone from ESRI comment on this.  From what I can tell the OBJECTID is being filtered out of the list of fields if you use AutoGenerateColumns.  I thought this was because of the code posted earlier in this thread but after some testing I dont ever see the OBJECTID field come through the OnAutoGeneratingColumn sub...  Its possible its a bug but the filtering seems to take place before the featuredatagrid is loaded, its interesting they check for the field but its never loaded...  I tired to find the filtering by looking for code looking at the LayerInfo.ObjectIdField but I dont see anything in the toolkit source code.  Must happen some where else in the base code.

Sorry for the rambling, it would be easy to add a property to be able to set if the objectid should be hidden or not.  Maybe in the next release this can be cleared up...

Chris
0 Kudos
jonathangamble
New Contributor III
Your rambling makes complete sense ... as I had the same thoughts!  I agree that the ObjectID should be displayed with an option to hide it.

Thanks again for the input.  I'll continue on with the way I have everything setup.

Cheers
Jon.
0 Kudos