Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Accessing ComboBoxes created by TitleTemplate

Sort Posts: Previous Next
  •  06-30-2008, 2:10 PM Post no. 13314

    Accessing ComboBoxes created by TitleTemplate

    I have a combobox in the TitleTemplate of a grid.  When a button click event fires, I want to loop through all of the comboboxes created by the TitleTemplate (x:Name="ThisComboBox" in the XAML below).  Can you please tell me how access these comboboxes in the code-behind?  (The XAML is listed below):

    <xcdg:DataGridControl x:Name="DetailDataGrid"

    Grid.Row="0"

    AutoCreateColumns="False"

    SelectionMode="Extended"

    ItemScrollingBehavior="Deferred"

    Margin="0,0,0,0"

    ItemsSource="{Binding Source={StaticResource FieldsDataSource}}"

    FontFamily="Arial">

     

    <xcdg:DataGridControl.Resources>

    <DataTemplate x:Key="ColumnTitleDataTemplate">

    <StackPanel Orientation="Vertical">

    <ComboBox x:Name="ThisComboBox">

    <ComboBoxItem IsSelected="True">One</ComboBoxItem>

    <ComboBoxItem>Two</ComboBoxItem>

    <ComboBoxItem>Three</ComboBoxItem>

    </ComboBox>

    <TextBlock Text="{Binding}" />

    </StackPanel>

    </DataTemplate>

    </xcdg:DataGridControl.Resources>

     

    <xcdg:DataGridControl.Columns>

    <xcdg:Column FieldName="One" Title="Title 1" TitleTemplate="{StaticResource ColumnTitleDataTemplate}" />

    <xcdg:Column FieldName="Two" Title="Title 2"

    TitleTemplate="{StaticResource ColumnTitleDataTemplate}" />

    <xcdg:Column FieldName="Three" Title="Title 3"

    TitleTemplate="{StaticResource ColumnTitleDataTemplate}" />

    <xcdg:Column FieldName="Four" Title="Title 4"

    TitleTemplate="{StaticResource ColumnTitleDataTemplate}" />

    </xcdg:DataGridControl.Columns>

    <xcdg:DataGridControl.View>

    <xcdg:TableView ShowScrollTip="True"

    UseDefaultHeadersFooters="False"

    ShowRowSelectorPane="True"

    ShowFixedColumnSplitter="True">

    <xcdg:TableView.FixedHeaders>

    <DataTemplate>

    <xcdg:ColumnManagerRow />

    </DataTemplate>

    </xcdg:TableView.FixedHeaders>

    </xcdg:TableView>

    </xcdg:DataGridControl.View>

    </xcdg:DataGridControl>

    Filed under: , ,
  •  06-30-2008, 4:44 PM Post no. 13315 in reply to 13314

    Re: Accessing ComboBoxes created by TitleTemplate

    Figured it out...

    bool fieldSelectedMoreThanOnce = false;

    ColumnManagerRow columnManagerRow = FindVisualChild<ColumnManagerRow>(DetailDataGrid);

    columnManagerRow.Cells[0].FindName("SalesPulseFieldsComboBox");

     

    for (int i = 0; i < columnManagerRow.Cells.Count; i++)

    {

    ContentPresenter contentPresenter = FindVisualChild<ContentPresenter>(columnManagerRow.CellsIdea);

    DataTemplate dataTemplate = (DataTemplate)DetailDataGrid.FindResource("ColumnTitleDataTemplate");

    ComboBox comboBox = (ComboBox)dataTemplate.FindName("ThisComboBox", contentPresenter);

    if (!selectedFields.Contains(comboBox.Text))

    {

    selectedFields.Add(comboBox.Text);

    }

    else

    {

    fieldSelectedMoreThanOnce = true;

    }

    }

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.