Select to view content in your preferred language

Add Functionality to FeatureDataGrid

1123
6
12-06-2011 06:59 AM
KeithGanzenmuller
Frequent Contributor
I have a featuredatagrid which displays information for selected parcels.
I want to add a button to it that exports the information for the parcels that are selected in the featuredatagrid.
I can export the info using a button but I would like to add the button to the bottom of the grid near the options button or add a menu item to the options menu.
I have edited the control templates before but it has been to remove or change the properties of the control parts. I can also navigate down to the to the parts by editing the controls template...so my question is if I add a button...here comes the dumb part...where does the code go for the click event functionality.
Thanks for any help or suggestions.
Keith
0 Kudos
6 Replies
DominiqueBroux
Esri Frequent Contributor
You can create your own control subclassing FeatureDataGrid.

Something like:
 
public class MyFeatureDataGrid : ESRI.ArcGIS.Client.Toolkit.FeatureDataGrid
{
  public override void OnApplyTemplate()
  {
    base.OnApplyTemplate();
    var myNewButton = GetTemplateChild("MyNewButton") as Button;
    if (myNewButton != null)
      myNewButton.Click += myNewButton_Click;
  }
  void myNewButton_Click(object sender, System.Windows.RoutedEventArgs e)
  {
    // TODO
    throw new System.NotImplementedException();
  }
}


Then you have to edit the template and add a button called "MyNewButton" (as you already done).
And finally you have to use this subclass in your xaml main control.
0 Kudos
KeithGanzenmuller
Frequent Contributor
Thanks Dominique, that is exactly what I need to do.
Anyone have similar code for VB?
0 Kudos
KeithGanzenmuller
Frequent Contributor
I subclassed ( I think) the FeatureDataGrid, added it in XAML.
The FDG receives the output of my selections perfectly.
I added an Export Selected button named "ExportButton" to the Options Popup Menus. The button appears in the menu when I run the project and click "Options".
Partial XAML of Options popup below:
<Grid Margin="5,0,0,0">
<Button x:Name="OptionsButton" Content=" Options... "/>
<Popup x:Name="PopupMenu" IsOpen="False">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" Background="TemplateBinding Background}" CornerRadius="1.5">
<StackPanel>                 <Button x:Name="ExportButton" Margin="5,0" Style="{StaticResource MenuButtonStyle}">
<TextBlock Margin="5" Text="Export Selection" VerticalAlignment="Center"/>
</Button>

My question is, inside my subclass, in VB .Net, how do I find my button to assign it's click event?
Thanks for any suggestions.
0 Kudos
KeithGanzenmuller
Frequent Contributor
This is what the class looks like:
So far I am trying to run the code and find the button but it always returns nothing.

Public Class NewFDG
    Inherits ESRI.ArcGIS.Client.Toolkit.FeatureDataGrid
    Public Sub New()
        MyBase.New()

        Dim myexportButton As Button = CType(GetTemplateChild("ExportSelectionButton"), Button)
        '    AddHandler myexportButton.Click, AddressOf myexportButton_Click
      
If myexportButton Is Nothing Then
           MessageBox.Show("Nothing")
End If



    End Sub

    'Private Sub myexportButton_Click(sender As Object, e As RoutedEventArgs)
    '    MessageBox.Show("Click") 'Throw New NotImplementedException
    'End Sub



End Class
0 Kudos
DominiqueBroux
Esri Frequent Contributor
You can't call GetTemplateChild in the constructor.
You have to do it by overriding OnApplyTemplate.
Something like:
Public Overrides Sub OnApplyTemplate()
  MyBase.OnApplyTemplate()
  Dim myNewButton = TryCast(GetTemplateChild("MyNewButton"), Button)
  If myNewButton IsNot Nothing Then
    myNewButton.Click += myNewButton_Click
End If
End Sub
0 Kudos
KeithGanzenmuller
Frequent Contributor
That worked PERFECTLY, the code found the button and executed the click event.

Thanks again to you.
0 Kudos