RowDetails questions

8 posts, 1 answers
  1. Randy Hompesch
    Randy Hompesch avatar
    148 posts
    Member since:
    Nov 2008

    Posted 26 Nov 2016 Link to this post

    Hi,

    I have a fairly complex setup as shown below. I am using row details to act as an editor for the selected row in the gridview. I have Expand mode set to single so only one row can be expanded at a time. My question is how to validate data before the move to another row, or try to navigate elsewhere, or close the app, etc.? As you can see from the xaml, I tried wiring up the RowEditEnded command to the RowEditEnded event, but it doesn't seem to ever fire.

    Any guidance would be greatly appreciated.

    Thanks ... Ed

     

     

    <telerik:RadGridView  x:Name="ssSamples"
        AutoGenerateColumns="False"  IsReadOnly="True"
        ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor,
                                                    AncestorType={x:Type UserControl} },
                                                    Path=DataContext.Samples}"
        SelectedItem="{Binding SelectedRow}"
        MaxHeight="500" RowIndicatorVisibility="Visible" RowDetailsVisibilityMode="VisibleWhenSelected"  
        >
        <telerik:EventToCommandBehavior.EventBindings>
            <telerik:EventBinding Command="{Binding RowDetailsVisibilityChangingCommand}" EventName="RowDetailsVisibilityChanging"  PassEventArgsToCommand="True"/>
            <telerik:EventBinding Command="{Binding RowEditEndedCommand}" EventName="RowEditEnded"  PassEventArgsToCommand="True"/>
     
        </telerik:EventToCommandBehavior.EventBindings>
        <telerik:RadGridView.Columns>
            <telerik:GridViewToggleRowDetailsColumn  ExpandMode="Single" />
            <telerik:GridViewDataColumn Width="auto" Header="Sample Key" DataMemberBinding="{Binding Sample.Sample_Key}"/>
            <telerik:GridViewDataColumn Width="auto" Header="Client Sample Id" DataMemberBinding="{Binding Sample.ClientSampleID}"/>
            <telerik:GridViewDataColumn Width="auto" Header="Arrival" DataMemberBinding="{Binding ArrivalDesc}"/>
            <telerik:GridViewDataColumn Width="auto" Header="Status" DataMemberBinding="{Binding Sample.Status}"/>
        </telerik:RadGridView.Columns>
        <telerik:RadGridView.RowDetailsTemplate>
            <DataTemplate>
                <Grid Width="Auto" HorizontalAlignment="Stretch">
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition  />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition  />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
     
                    <Label Grid.Row="0" Grid.Column="0" Content="Client Sample Id:" VerticalAlignment="Top"  />
                    <TextBox x:Name="txtSampleId" Grid.Row="0" Grid.Column="1"
                                            HorizontalAlignment="Left" Text="{Binding Sample.ClientSampleID}" Width="250" />
                    <Label Grid.Row="1" Grid.Column="0" Content="Priority:" VerticalAlignment="Top" />
                    <telerik:RadComboBox x:Name="ddlPriority" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left"
                                            VerticalAlignment="Top" Width="250"
                                            SelectedValuePath="Tag"
                                            SelectedValue="{Binding Sample.Priority, UpdateSourceTrigger=PropertyChanged }"
                                            SelectedIndex="0"
                                    >
                        <telerik:RadComboBoxItem  Content="Low" Tag="Low"/>
                        <telerik:RadComboBoxItem  Content="Medium" Tag="Medium"/>
                        <telerik:RadComboBoxItem  Content="High" Tag="High"/>
                    </telerik:RadComboBox>
                    <Label Grid.Row="2" Grid.Column="0" Content="Arrival:" VerticalAlignment="Top" />
                    <telerik:RadComboBox x:Name="ddlArrival" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left"
                                        VerticalAlignment="Top" Width="250" SelectedValuePath="Tag"
                                        SelectedValue="{Binding Sample.Arrival, UpdateSourceTrigger=PropertyChanged }"
                                        SelectedIndex="0"
                                    >
                        <telerik:RadComboBoxItem  Content="No" Tag="0"/>
                        <telerik:RadComboBoxItem  Content="Park" Tag="1"/>
                        <telerik:RadComboBoxItem  Content="Returned" Tag="2"/>
                        <telerik:RadComboBoxItem  Content="Discarded" Tag="3"/>
                    </telerik:RadComboBox>
                    <Label Grid.Row="3" Grid.Column="0" Content="Status:" VerticalAlignment="Top" />
                    <telerik:RadComboBox x:Name="ddlStatus" Grid.Row="3" Grid.Column="1" HorizontalAlignment="Left"
                                            VerticalAlignment="Top" Width="250"
                                            SelectedValuePath="Tag"
                                            SelectedValue="{Binding Sample.Status, UpdateSourceTrigger=PropertyChanged }"
                                            SelectedIndex="0"
                                    >
                        <telerik:RadComboBoxItem Content="Incomplete" Tag="Incomplete"/>
                        <telerik:RadComboBoxItem Content="Complete" Tag="Complete"/>
                    </telerik:RadComboBox>
                    <Label Grid.Row="4" Grid.Column="0" Content="Description:" VerticalAlignment="Top" />
                    <TextBox x:Name="txtSampleDesc" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan ="2"
                                        Text="{Binding Sample.SampleDescription }" Height="60" Width="250" HorizontalAlignment="Left"
                                        TextWrapping="WrapWithOverflow" AcceptsReturn="True"  VerticalScrollBarVisibility="Auto"
                                        VerticalAlignment="Top" VerticalContentAlignment="Top"                 
                                    />
     
                    <Label Grid.Row="5" Grid.Column="0" Content="Comments:" VerticalAlignment="Top" />
                    <TextBox x:Name="txtSampleComments" Grid.Row="5" Grid.Column="1"  Grid.ColumnSpan ="2"
                                            Text="{Binding Sample.Comments }" Height="60" Width="250" HorizontalAlignment="Left"
                                            TextWrapping="WrapWithOverflow" AcceptsReturn="True"
                                            VerticalScrollBarVisibility="Auto" VerticalAlignment="Top" VerticalContentAlignment="Top"                 
                                />
                    <Label Content="Associated Techniques:" Grid.Row="0" Grid.Column="2" HorizontalAlignment="Left" HorizontalContentAlignment="Left"  Width="350" Height="auto"/>
                    <StackPanel Orientation="Vertical" Grid.Row="1" Grid.Column="2" Grid.RowSpan ="5" MaxHeight="210" >
                        <ItemsControl x:Name ="lstTechniques" ItemsSource="{Binding AssociatedTechniques, Mode=TwoWay }"
                                                    Margin="5,0,0,0"
                                                    >
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
     
                                    <support:UniformGridWithOrientation Orientation="Vertical"  Columns="4"  />
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate >
                                    <CheckBox Content="{Binding TechniqueID}"
                                                            IsChecked="{Binding IsSelected, Mode=TwoWay}"
                                                            ToolTip="{Binding TechniqueName}"
                                          
                                                    >
                                    </CheckBox>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
     
                    </StackPanel>
                </Grid>
            </DataTemplate>
        </telerik:RadGridView.RowDetailsTemplate>
    </telerik:RadGridView>
  2. Randy Hompesch
    Randy Hompesch avatar
    148 posts
    Member since:
    Nov 2008

    Posted 26 Nov 2016 in reply to Randy Hompesch Link to this post

    Forgot to mention that I'm looking for an MVVM (Prism 6) solution.

    Thanks ... Ed

     

  3. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1170 posts

    Posted 28 Nov 2016 Link to this post

    Hello Randy,

    What I can suggest in this scenario is to integrate RadDataForm with RadGridView as demonstrated in the "Integration with RadGridView rowdetails" demo of our WPF Controls Examples so that you can easily benefit from RadDataForm's validation capabilities.

    For your convenience, I'm attaching a sample project, demonstrating the approach I have in mind. Please have a look at it and let me know whether this would work for you.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
  4. Randy Hompesch
    Randy Hompesch avatar
    148 posts
    Member since:
    Nov 2008

    Posted 29 Nov 2016 in reply to Dilyan Traykov Link to this post

    Thanks for the example. I tried running it and when  I edit a field directly on a row (Not in the dataform), and then move to another row, the RowEditEnded event fires. However, if I edit the same field in the dataform and hit OK and/or move to another row, the event does not fire. What am I missing? Ideally, I would like the gridview rows to be readonly. I only want them to be able to make changes in the dataform. While we are at it, what I'd really like is to get the RowEditEnded event to be fired when they hit the OK button on the RadDataForm. Would this be possible?

    Thanks ...  Ed

     

  5. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1170 posts

    Posted 29 Nov 2016 Link to this post

    Hello Ed,

    When you're editing the item through RadDataForm, you will need to handle its EditEnded event rather than RadGridView's RowEditEnded event which will not get fired as, technically, you're not editing the row, you're editing the bound data item. Please let me know if this would work for you.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
  6. Randy Hompesch
    Randy Hompesch avatar
    148 posts
    Member since:
    Nov 2008

    Posted 29 Nov 2016 in reply to Dilyan Traykov Link to this post

    Still trying!
    I added the event binding to the raddataform as show below and I never got the event. I set  a  breakpoint on the OnEditEnded function but never reached it. Am I doing something wrong (probably! )?

    Thanks ... Ed

     

    <telerik:RadGridView.RowDetailsTemplate>
        <DataTemplate>
     
            <telerik:RadDataForm CurrentItem="{Binding}" AutoGenerateFields="False"
                    EditTemplate="{StaticResource RowDetailsTemplate}"
                    NewItemTemplate="{StaticResource RowDetailsTemplate}"
                    ReadOnlyTemplate="{StaticResource RowDetailsTemplate}"
                    CommandButtonsVisibility="All"
                        >
                <telerik:EventToCommandBehavior.EventBindings>
                    <telerik:EventBinding Command="{Binding EditEndedCommand}" EventName="EditEnded" PassEventArgsToCommand="True"/>   
                </telerik:EventToCommandBehavior.EventBindings>                           
            </telerik:RadDataForm>
        </DataTemplate>
    </telerik:RadGridView.RowDetailsTemplate>

     

    public ICommand EditEndedCommand { get; set; }

    // in my constructor of the vm

    EditEndedCommand = new Telerik.Windows.Controls.DelegateCommand(OnEditEnded);

     

    private void OnEditEnded(object parms)
    {
    }

     

  7. Answer
    Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1170 posts

    Posted 29 Nov 2016 Link to this post

    Hello Ed,

    Since RadDataForm is defined in a DataTemplate, you will need to specify the source for the command binding. Here are a couple of suggestions:

    Suggestion 1)
    <telerik:RadDataForm CurrentItem="{Binding}" CommandButtonsVisibility="All">
        <telerik:EventToCommandBehavior.EventBindings>
            <telerik:EventBinding Command="{Binding DataContext.EditEndedCommand, RelativeSource={RelativeSource AncestorType=telerik:RadGridView}}" EventName="EditEnded" PassEventArgsToCommand="True"/>
        </telerik:EventToCommandBehavior.EventBindings>
    </telerik:RadDataForm>

    Suggestion 2)
    <telerik:RadDataForm CurrentItem="{Binding}" CommandButtonsVisibility="All">
        <telerik:EventToCommandBehavior.EventBindings>
            <telerik:EventBinding Command="{Binding EditEndedCommand, Source={StaticResource MyViewModel}}" EventName="EditEnded" PassEventArgsToCommand="True"/>
        </telerik:EventToCommandBehavior.EventBindings>
    </telerik:RadDataForm>

    I hope you find this information helpful. Do let me know if you need any further assistance on the matter.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
  8. Randy Hompesch
    Randy Hompesch avatar
    148 posts
    Member since:
    Nov 2008

    Posted 29 Nov 2016 in reply to Dilyan Traykov Link to this post

    Tada!!! I knew there had to be some magic dust I needed to sprinkle on it. Now I can put the cake in the oven!

    Thanks ... Ed

     

Back to Top