Accessing a DevExpress TableView within a DevExpress TreeListView Column

209 Views Asked by At

I have dxg:TableView which sits inside the column of a dxg:TreeListView. This all works fine, however when I attempt to access the dxg:TableView in the code behind, it is invisible to the interpreter. I can access the TreeListView without issue using...

// Works as Expected.

var focusedState = (StateType)StatesView.FocusedNode.Content; 

// LocationView is Not visible to debugger or interpreter.

var focusedLocationInStateRow = (LocationType)LocationView.FocusedNode.Content; 

My goal is to get the Location row (can be 1 of many) selected within the State row. Locations are a collection within the State data model. Records are to be removed via the DeleteLocationRow Button method.

private void DeleteLocationRow(object sender, RoutedEventArgs e)

How does one access a TableView/GridView object within a TreeListView Column?

WPF Markup:

           <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <dxg:TreeListControl x:Name="StateGrid"
                                 AllowLiveDataShaping="True"
                                    SelectionMode="Cell"
                                Margin="16.5,0,0,0"
                                     SelectedItem="{Binding SelectedState}"
                                 ItemsSource="{Binding MyStates}">
                    <dxg:TreeListControl.Resources>
                        <Style x:Key="SummaryStyle" TargetType="Run">
                            <Setter Property="FontWeight" Value="Bold"/>
                            <Setter Property="dxp:TextExportSettings.FontFamily" Value="Arial Narrow"/>
                        </Style>
                    </dxg:TreeListControl.Resources>
                    <dxg:TreeListControl.Columns>
                        <dxg:TreeListColumn Header="Name" Width="190" FieldName="Name" />                               
                        <dxg:TreeListColumn Header="State Id" Width="80" FieldName="StateId" />
                        </dxg:TreeListColumn>
                        <dxg:TreeListColumn
                            AllowEditing="true"
                            Header="Locations"
                            Width="Auto">
                            <dxg:TreeListColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding RowData.Row.Locations, Converter={valueConverters:LocaleIdsTextValueConverter}}"/>
                                </DataTemplate>
                            </dxg:TreeListColumn.CellTemplate>
                            <dxg:TreeListColumn.CellEditTemplate>
                                <DataTemplate>
                                    <dxg:GridControl
                                        x:Name="LocationGrid" 
                                        ItemsSource="{Binding RowData.Row.Locations}"
                                        HorizontalAlignment="Stretch" 
                                        Height="100"
                                        Width="525"
                                        AutoGenerateColumns="AddNew" 
                                        EnableSmartColumnsGeneration="True"
                                        SelectionMode="Cell">
                                        <dxg:GridControl.Columns>
                                            <dxg:GridColumn Header="LocationId" FieldName="LocationId" SortIndex="0" Width="100" AllowEditing="true">
                                                <dxg:GridColumn.EditSettings>
                                                    <dxe:SpinEditSettings MaskType="Numeric" Mask="d" MinValue="1" MaxValue="100"  
                                                        ShowText="{Binding Path=RowData.Row.IsNode}"  
                                                        IsTextEditable="{Binding Path=RowData.Row.IsNode}"  
                                                        IsEnabled="{Binding Path=RowData.Row.IsNode}" />
                                                </dxg:GridColumn.EditSettings>
                                            </dxg:GridColumn>
                                            <dxg:GridColumn Header="Incorporated Date" SortIndex="1" SortOrder="Ascending" Width="110" FieldName="IncorporatedDate" AllowEditing="true">
                                                <dxg:GridColumn.EditSettings>
                                                    <dxe:DateEditSettings MaskType="DateTime"
                                                          Mask="MM/dd/yyyy HH:mm"
                                                          MaskUseAsDisplayFormat="True"
                                                          dxe:DateTimeMaskOptions.DateTimeKind="Local"
                                                          NullText=""
                                                          AllowNullInput="True"
                                                          ValidateOnEnterKeyPressed="True"
                                                          ValidateOnTextInput="True">
                                                        <dxe:DateEditSettings.StyleSettings>
                                                            <dxe:DateEditNavigatorWithTimePickerStyleSettings/>
                                                        </dxe:DateEditSettings.StyleSettings>
                                                    </dxe:DateEditSettings>
                                                </dxg:GridColumn.EditSettings>
                                            </dxg:GridColumn>
                                            <dxg:GridColumn Header="Delete Rows"  Width="100">
                                                <dxg:GridColumn.CellTemplate>
                                                    <DataTemplate>
                                                        <Button Click="DeleteLocationRow">
                                                            Delete Row
                                                        </Button>
                                                    </DataTemplate>
                                                </dxg:GridColumn.CellTemplate>
                                            </dxg:GridColumn>
                                        </dxg:GridControl.Columns>
                                        <dxg:GridControl.View>
                                            <dxg:TableView
                                                Name="LocationView"
                                                NavigationStyle="Cell"
                                                AutoScrollOnSorting="False"
                                                NewItemRowPosition="Bottom"
                                                HorizontalScrollbarVisibility="Hidden"
                                                ShowColumnHeaders="True"
                                                ImmediateUpdateRowPosition="False"
                                                AllowSorting="True"
                                                AllowEditing="True"
                                                ShowIndicator="True"
                                                ShowGroupPanel="False"
                                                ShowTotalSummary="False"
                                                ShowFilterPanelMode="Never"
                                                CellStyle="{StaticResource CustomLocaleCellStyle}"
                                                ShowAutoFilterRow="False">
                                            </dxg:TableView>
                                        </dxg:GridControl.View>
                                    </dxg:GridControl>
                                </DataTemplate>
                            </dxg:TreeListColumn.CellEditTemplate>
                        </dxg:TreeListColumn>
                        <dxg:TreeListColumn Header="City" Width="60"  FieldName="City" />
                    </dxg:TreeListControl.Columns>
                    <dxg:TreeListControl.View>
                        <dxg:TreeListView Name="StatesView"
                                      TreeDerivationMode="HierarchicalDataTemplate"
                                      AutoExpandAllNodes="True"
                                      AllowConditionalFormattingMenu="True"
                                      AutoScrollOnSorting="False"
                                      ShowEmptyText ="False"
                                      AutoWidth="False"
                                      ShowExpandButtons="True"
                                      ShowRootIndent="True"
                                      ShowAutoFilterRow="True"
                                      NavigationStyle="Cell"
                                      ImmediateUpdateRowPosition="False"
                                     EnableImmediatePosting ="True"
                                        AllowSorting="False"
                                        AllowEditing="True"
                                        ShowIndicator="False"
                                        ClipboardCopyOptions="All"
                                        ClipboardMode="Formatted"
                                        ShowTotalSummary="True"
                                        ShowFilterPanelMode="Never"
                                        EditorShowMode="MouseDown"
                                        RowStyle="{StaticResource FocusedRowStyle}"
                                        CellStyle="{StaticResource CustomCellStyle}"
                                       AllowDataUpdateFormatConditionMenu="True">
                            <dxg:TreeListView.ColumnHeaderTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding}" TextWrapping="Wrap"/>
                                </DataTemplate>
                            </dxg:TreeListView.ColumnHeaderTemplate>
                        </dxg:TreeListView>
                    </dxg:TreeListControl.View>
                </dxg:TreeListControl>
            </Grid>
1

There are 1 best solutions below

0
user2284452 On

I was able to access the row information using the DataContext derived from the Button event.

private void DeleteLocationRow(object sender, System.EventArgs e)
        {
            _isUpdating = true;
            // Remove Row from Data set
            var m = MessageBox.Show("Do you really want to delete this row?", "Delete Row", MessageBoxButton.YesNo);
            if (m == MessageBoxResult.Yes)
            {
                //Get the button that raised the event
                var btn = (Button)sender;

                //Get the row that contains this button
                var dRow = ((GridCellData)btn.DataContext).Row;
                
                var localIdRow = (LocationInfo)dRow; // Convert to My Type in Column Row
                
                // Delete Record from OPR and LPC
                LocaleIdManager.DeleteLocationId(SelectedDatabases, localIdRow);                

            }