GridView SelectedItem

3 posts, 0 answers
  1. Brian
    Brian avatar
    2 posts
    Member since:
    Dec 2011

    Posted 17 Jan 2012 Link to this post

    Hello,

    I have a RadGridView control bound to a CollectionViewSource.View.  I also have the SelectedItem bound to a VM Property with Mode=TwoWay.  I have a RadDataForm bound to the same collection as the RadGridView.  When the Grid first comes up, everything is fine.  When I select an item, things are fine.  The selected item in the grid appears in read-only mode in the RadDataForm.  When I click on the edit icon, change the value of a field, then click the Commit button the selected item moves to the row before the one I am editing but the highlighted row is the one I want to edit.  Also in my command method, the selected item is not what I edited.

    Properties of the RadGridView:
    <telerik:RadGridView Name="significantActivities" 
                                     VerticalAlignment="Top" 
                                     HorizontalAlignment="Left"
                                     CanUserDeleteRows="False" 
                                     CanUserFreezeColumns="False" 
                                     CanUserInsertRows="False" 
                                     AutoGenerateColumns="False" 
                                     AutoExpandGroups="True" 
                                     IsReadOnly="True"
                                     ColumnWidth="*"
                                     ItemsSource="{Binding SignificantActivityCollection.View}" 
                                     SelectedItem="{Binding SelectedSignificantActivity, Mode=TwoWay}">

    Here is the code for SelectedSignificantActivity Dependency Property
    public Model.SignificantActivity SelectedSignificantActivity
            {
                get
                {
                    return _selectedSignificantActivity; ;
                }
                set
                {
                    if (_selectedSignificantActivity != value)
                    {
                        _selectedSignificantActivity = value;
     
                        // Update bindings no broadcast
                        RaisePropertyChanged(SelectedSignificantActivityPropertyName);
                    }
                }
            }
    Here is the code in the Command method:
    DataService.SaveActivity(result => DispatcherHelper.CheckBeginInvokeOnUI(() =>
                                             {
                                                 if (result)
                                                 {
                                                 }
                                             }),
                                         SelectedSignificantActivity);

    And here is the properites for the RadDataForm:
    <telerik:RadDataForm x:Name="dataForm"
                                     ItemsSource="{Binding SignificantActivityCollection.View}"
                                     AutoGenerateFields="False"
                                     CommandButtonsVisibility="Add,Edit,Cancel,Commit"
                                     LabelPosition="Above"
                                     ReadOnlyTemplate="{StaticResource significantActivityReadOnlyTemplate}"
                                     EditTemplate="{StaticResource significantActivityEditTemplate}"
                                     NewItemTemplate="{StaticResource significantActivityEditTemplate}" 
                                     VerticalContentAlignment="Stretch" 
                                     HorizontalContentAlignment="Stretch">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="EditEnded">
                            <mvvmLtCommanding:EventToCommand Command="{Binding EditSignificantActivityCommand}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </telerik:RadDataForm>

    Any idea why my SelectedSignificantActivity is not set to the item I am actually editing?
  2. Brian
    Brian avatar
    2 posts
    Member since:
    Dec 2011

    Posted 17 Jan 2012 Link to this post

    Ok, I was able to apply what I would call "A HACK!".  I created an EventTrigger on the BeginningEdit event.  In my VM, I created a private field to hold the selected value when the code enters the BeginningEdit event.  Then when I am finished editing, I send the value of the field to the database.  This works.  The one thing I noticed is the object that is being edited goes to the bottom of the grid when the editing is completed.  But the highlighted field in the grid is still at the original position (wrong item and setting the selected item to the wrong item as well).
    This fixes the editing item, but breaks the adding of an item.
  3. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 20 Jan 2012 Link to this post

    Hi,

    I've tried to simulate your problem unfortunately to no avail. Could you please send me a sample application which I can debug on my side in order to see what is going on?
    Thank you in advance.

    P.S. You need to open a support ticket in order to be able to attach files.

    Regards,
    Nedyalko Nikolov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top