Select to view content in your preferred language

Adding columns to FeatureDataGrid

749
2
Jump to solution
08-27-2012 07:27 AM
KenDoman
Frequent Contributor
Is there a way to add extra columns to FeatureDataGrid while AutoGenerateColumns=True? For example, I want to add a column at the beginning of the featuredatagrid with a closing image that lets the user remove the graphic from the map when the image is clicked.
0 Kudos
1 Solution

Accepted Solutions
KenDoman
Frequent Contributor
Thanks for the help. I figured out that if you add columns using DataGridTemplateColumn, but keep AutoGenerateColumns = True, it autogenerates the columns after the columns you hard code.

Also, if you want a specific column first, and you know it's always going to be in your results, you can hard code it, then use the AutoGeneratingColumn function to cancel that column when it's autogenerated.

[HTML]
<esri:FeatureDataGrid x:Name="MyDataGrid" AutoGenerateColumns="True" Map="{Binding ElementName=MyMap}" GraphicsLayer="{Binding ElementName=MyMap, Path=Layer[myGraphicsLayer]}">

<esri:FeatureDataGrid.Columns>

                <slData:DataGridTemplateColumn Header="Remove">
                    <slData:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <HyperlinkButton Click="RemoveSelected_Click">
                                <HyperlinkButton.Background>
                                    <ImageBrush ImageSource="remove.png" />
                                </HyperlinkButton.Background>
                            </HyperlinkButton>
                        </DataTemplate>
                    </slData:DataGridTemplateColumn.CellTemplate>
                </slData:DataGridTemplateColumn>

</esri:FeatureDataGrid.Columns>

</esri:FeatureDataGrid>
[/HTML]

Private Sub RemoveSelected_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)         Dim test As List(Of Graphic) = MyDataGrid.SelectedGraphics          For Each g As Graphic In test             myGraphicsLayer.Graphics.Remove(g)         Next g      End Sub

View solution in original post

0 Kudos
2 Replies
SanajyJadhav
Deactivated User
I had done it but AutoGenerateColumns was false.Below is my XAML.

[HTML]
<esri:FeatureDataGrid x:Name="dgScheduling" AutoGenerateColumns="False"
      Margin="0,0,0,0" FontSize="9.667" CanUserReorderColumns="False"
      IsReadOnly="True" ScrollViewer.HorizontalScrollBarVisibility="Auto"
      ScrollViewer.VerticalScrollBarVisibility="Auto" FrozenColumnCount="1">
            <sdk:DataGrid.Columns>
              
               <sdk:DataGridTemplateColumn Width="50" CanUserResize="False" CanUserReorder="False" CanUserSort="False">                
                  <sdk:DataGridTemplateColumn.CellTemplate>
                     <DataTemplate>
                        <Grid>
                           <StackPanel Orientation="Horizontal">
                       
<Button Content="Edit" x:Name="btnEdit" Margin="2,0,0,2" Click="btnEdit_Click" Style="{StaticResource btnEdit}" ToolTipService.ToolTip="Edit" />
    
                         <Button Content="Pano" x:Name="btnPano"  Margin="2,0,0,2" Style="{StaticResource buttonPano}" Click="btnPano_Click" ToolTipService.ToolTip="View Pano" />
                           </StackPanel>
                        </Grid>
                     </DataTemplate>
                  </sdk:DataGridTemplateColumn.CellTemplate>
               </sdk:DataGridTemplateColumn>
            </sdk:DataGrid.Columns>            
         </esri:FeatureDataGrid>
[/HTML]

Hope this helps.
0 Kudos
KenDoman
Frequent Contributor
Thanks for the help. I figured out that if you add columns using DataGridTemplateColumn, but keep AutoGenerateColumns = True, it autogenerates the columns after the columns you hard code.

Also, if you want a specific column first, and you know it's always going to be in your results, you can hard code it, then use the AutoGeneratingColumn function to cancel that column when it's autogenerated.

[HTML]
<esri:FeatureDataGrid x:Name="MyDataGrid" AutoGenerateColumns="True" Map="{Binding ElementName=MyMap}" GraphicsLayer="{Binding ElementName=MyMap, Path=Layer[myGraphicsLayer]}">

<esri:FeatureDataGrid.Columns>

                <slData:DataGridTemplateColumn Header="Remove">
                    <slData:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <HyperlinkButton Click="RemoveSelected_Click">
                                <HyperlinkButton.Background>
                                    <ImageBrush ImageSource="remove.png" />
                                </HyperlinkButton.Background>
                            </HyperlinkButton>
                        </DataTemplate>
                    </slData:DataGridTemplateColumn.CellTemplate>
                </slData:DataGridTemplateColumn>

</esri:FeatureDataGrid.Columns>

</esri:FeatureDataGrid>
[/HTML]

Private Sub RemoveSelected_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)         Dim test As List(Of Graphic) = MyDataGrid.SelectedGraphics          For Each g As Graphic In test             myGraphicsLayer.Graphics.Remove(g)         Next g      End Sub
0 Kudos