This is a migrated thread and some comments may be shown as answers.

GridView SelectedItem

2 Answers 33 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 17 Jan 2012, 07:23 AM
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 Answers, 1 is accepted

Sort by
0
Brian
Top achievements
Rank 1
answered on 18 Jan 2012, 05:06 AM
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.
0
Nedyalko Nikolov
Telerik team
answered on 20 Jan 2012, 09:33 AM
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 >>

Tags
GridView
Asked by
Brian
Top achievements
Rank 1
Answers by
Brian
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Share this question
or