GridView SelectedItem update issue

16 posts, 1 answers
  1. Calabonga
    Calabonga avatar
    29 posts
    Member since:
    Nov 2009

    Posted 18 Aug 2010 Link to this post

    Hi. I have another trouble with grid update (SelectedItem)
    Briefly...
    I'm using:
    - Silverlight
    - MVVM (library MVVM light)
    - RIA (DomainDataSource)
    - RadGridView (2010.2 812 (Aug 12, 2010))
    Please, look at the picture named map_of_actions.png (see attachments).
    Main ViewModel (Which name is HomeViewModel) has 3 ViewModel. They are all linked.
    1. ACTION 1: When I click on Master1 treeview (DepartmentTreeViewModel) the  Detail1 (GridView) is reloaded details records (at map it ACTION 2).
    2.ACTION 3: When I click on Master2 gridview (StaffViewModel) the Detail2 (GridView) is reloaded details records for master2 (at map see ACTION 4).
    3. And now the issue: how I can make GridView (Master2) update your selectedItem for Deteil2. When I click Master1 DETAIL2 must update too! But Master2 SelectedItem not updated.

    I was try many events on gridview, but they are not fired when DomainDataSource event LoadedData completed And also I was try the DomainDataSource event LoadedData, but I can't find solution HOW can gridview make your SelectedItem updated (for example, just set first loaded item selected).

    Same piece of code
    StaffView.xaml:
    namespaces

    xmlns:qph="clr-namespace:BusinessApplication.Helpers"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:clb="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4"







    grid and domaindatasource

    <sdk:RadGridView HorizontalAlignment="Stretch"
                                 Width="auto"
                                 x:Name="grid"
                                 PropertyChanged="grid_PropertyChanged"
                                 SelectionMode="Single"
                                 IsSynchronizedWithCurrentItem="True"
                                 ItemsSource="{Binding ElementName=DataSource, Path=Data}"
                                 AutoGenerateColumns="False">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="SelectionChanged">
                            <clb:EventToCommand Command="{Binding Path=SelectionChangedCommand}"
                                                CommandParameter="{Binding ElementName=grid}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                    <sdk:RadGridView.Columns>
                        <sdk:GridViewDataColumn Header="Должность"
                                                DataMemberBinding="{Binding Path=JobTitle.Name}" />
                        <sdk:GridViewDataColumn Header="DepartmentTree"
                                                DataMemberBinding="{Binding Path=DepartmentTree.Name}" />
                        <sdk:GridViewDataColumn Header="Salary"
                                                DataMemberBinding="{Binding Path=Salary}" />
                    </sdk:RadGridView.Columns>
                </sdk:RadGridView>
                <riaControls:DomainDataSource AutoLoad="True"
                                              Height="0"
                                              LoadSize="60"
                                              LoadDelay="00:00:01"
                                              Name="DataSource"
                                              QueryName="{Binding Path=DetailInfo.CurrentQueryName}"
                                              DomainContext="{Binding Path=Data.BridgeContext}"
                                              Width="0"
                                              qph:QueryParametersHelper.DetailInfo="{Binding Path=DetailInfo}"
                                              FilterOperator="And">
                </riaControls:DomainDataSource>

    Class QueryParametersHelper

    #region DetailInfo
      
            /// <summary>
            /// DetailInfo Attached Dependency Property
            /// </summary>
            public static readonly DependencyProperty DetailInfoProperty =
                DependencyProperty.RegisterAttached("DetailInfo", typeof(DetailDefinition), typeof(DomainDataSource),
                    new PropertyMetadata(null, OnDetailInfoChanged));
      
            /// <summary>
            /// Gets the DetailInfo property.  This dependency property 
            /// indicates ....
            /// </summary>
            public static DetailDefinition GetDetailInfo(DependencyObject d)
            {
                return (DetailDefinition)d.GetValue(DetailInfoProperty);
            }
      
            /// <summary>
            /// Sets the DetailInfo property.  This dependency property 
            /// indicates ....
            /// </summary>
            public static void SetDetailInfo(DependencyObject d, DetailDefinition value)
            {
                d.SetValue(DetailInfoProperty, value);
            }
      
            /// <summary>
            /// Handles changes to the DetailInfo property.
            /// </summary>
            private static void OnDetailInfoChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                DomainDataSource dds = (DomainDataSource)d;
                if (dds != null)
                {
                    DetailDefinition detail = (DetailDefinition)e.NewValue;
                    detail.DomainDataSource = dds;
                }
            }
      
            #endregion

    class StaffViewModel command SelectionChangedCommand

    #region команда SelectionChangedCommand
      
            /// <summary>
            /// Calabonga: Команда SelectionChangedCommand 
            /// </summary>
            public RelayCommand<object> SelectionChangedCommand
            {
                get
                {
                    return new RelayCommand<object>((e) => this.SelectionChangedCommandExecute(e),
                        (e) => this.CanExecuteSelectionChanged(e));
                }
            }
      
            /// <summary>
            /// Calabonga: Процедура выполняет команды SelectionChangedCommand
            /// </summary>
            private void SelectionChangedCommandExecute(object e)
            {
                // выполнение команды SelectionChanged
                object currentItem = ((RadGridView)e).CurrentItem;
                SelectedId = ((Staff)currentItem).Id;
            }
            /// <summary>
            /// Calabonga: Свойство проверки возможности выполнения команды SelectionChangedCommand()
            /// </summary>
            private bool CanExecuteSelectionChanged(object e)
            {
      
                // разрешен ли запуск команды
                return e != null;
      
            }
      
            #endregion // end команда SelectionChangedCommand

    And the last code of class StaffViewModel property SelectedId:

    #region SelectedId
           private int selectedId = -1;
           public int SelectedId
           {
               get { return selectedId; }
               set
               {
                   if (selectedId == value) return;
                   selectedId = value;
                   RaisePropertyChanged("SelectedId");
                   Messenger.Default.Send(selectedId, "Staff");
               }
           }
           #endregion


     

     

    P.S.: PersonViewModel class has the same properties and methods.

    Please help me. GridView with Persons entityties must be updated too when I change selection on TreeView (MASTER1)!!!

  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 19 Aug 2010 Link to this post

    Hello Calabonga,

    May I ask you for some clarification? I would like to better understand the relationship between the different views. For example, you say that when you select something on the TreeView the master grid (Master1) should change its selection - what is the criteria for this selection change? If "Р С Ц" is selected what should be the selected item of Master1?

    Similarly how is the staff listed in Master1 related to the people listed in Detail2? 

    All the best,
    Milan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Calabonga
    Calabonga avatar
    29 posts
    Member since:
    Nov 2009

    Posted 19 Aug 2010 Link to this post

    Let me explain. Please look at the attachment file (db_table). This is a part of our database, but you can see a same relations on it.
    Described example just another Master-Detail or I would say (MASTER1)-(DETAIL1=MASTER2)-(DETAIL2). :)

    Master1 linked with Detail1 and in turn Detail1 is a master table for Detail2. So if I change selection in treeview Detail1 will automatically refreshed, AND if it changed (the GridView SelectedItem changed too)  I need to refresh a second gridview which named Detail2 and linked with Master2.

    Sorry for my poor engish. If you're not understand I can make a short  video from screen to show how it works now, and show how would I like to make it work.

    P.S.: thanks for quick answer

  5. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 23 Aug 2010 Link to this post

    Hello Calabonga,

    Okay I guess I get it now. When you  select a department from the TreeView all Staff items for that particular department should be displayed in Master2 and when an item in Master2 is selected, Details2 should display all People that are related to the currently selected Staff in Master2. Is that correct?


    Sincerely yours,
    Milan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Calabonga
    Calabonga avatar
    29 posts
    Member since:
    Nov 2009

    Posted 23 Aug 2010 Link to this post

    YES!!! It correct. And now this work that way. But I do not need to click on the Master2, I want to update DETAIL2 automatically. I tried to find some event, and subscribe to it using EventToCommand (MVVM Light library), but did not find anything suitable. Updates are not happening because DomainDataSource event after data loaded did not set SelectedItem and event SelectionChaged not firing.

    I need to updates data in the tables occur one after another for.

    Please help!
  7. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 27 Aug 2010 Link to this post

    Hi Calabonga,

    That seems strange. If RadGridView is bound to an ICollectionView (DomainDataSource.Data is ICollectionView) the first item of the grid should be selected automatically and SelectionChanged should also be raised. You can also try to set IsSynchronizedwithCurrentItem to true to check is the first item will be automatically selected.

    Best wishes,
    Milan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Calabonga
    Calabonga avatar
    29 posts
    Member since:
    Nov 2009

    Posted 29 Aug 2010 Link to this post

    As You can see in code I'm already set up "true" in IsSynchronizedWithCurrentItem paremeter, and the radgridview is set up the first item as SelectedItem... But SelectionChanded evet did't fired!!! And that's why the second DETEAL is not start to update!!!

    Please, see the video made by me (screencast) to understand my problem!!! On this video you can see the problem.
  9. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 30 Aug 2010 Link to this post

    Hi Calabonga,

    Well, I tried to bind the grid in a similar manner and SelectionChanged is raised when grid is loaded. Could you please subscribe to SelectionChanged and check if SelectionChanged is called when the grid's ItemSource is changed. If SelectionChanged is raised the problem is in the application itself. 


    Regards,
    Milan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Calabonga
    Calabonga avatar
    29 posts
    Member since:
    Nov 2009

    Posted 30 Aug 2010 Link to this post

    Because I could not explain, you can't understand. And now you will see the problem. In this video you can understand my problem.

    Sorry, my enlish is poor.

    Please, help me to solve this problem.

  11. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 31 Aug 2010 Link to this post

    Hello Calabonga,

    Judging from the the video my theory about the problem is correct. Unfortunately it is a bit difficult to determine the cause of the problem just by looking at the videos or the sample code that you have submitted. Can we take a look at the application itself?


    Best wishes,
    Milan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  12. Calabonga
    Calabonga avatar
    29 posts
    Member since:
    Nov 2009

    Posted 31 Aug 2010 Link to this post

    I can send to you application which you saw on the video, but I can't send database... I can send SQL script to generate. Is it Ok?
  13. Answer
    Milan
    Admin
    Milan avatar
    1989 posts

    Posted 31 Aug 2010 Link to this post

    Hello Calabonga,

    Sounds great. If the data or the application contains some sensitive information you can open a support ticked and attach all data to this ticket - that way the data will not be public.


    Best wishes,
    Milan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  14. Calabonga
    Calabonga avatar
    29 posts
    Member since:
    Nov 2009

    Posted 31 Aug 2010 Link to this post

    I was created a ticket. I send a project of application, but the Telerik.*.dll had to be removed to facilitate weight uploads.

    The number of Ticket is:
     Your ticket ID is : 344067

    I hope this will help to solve the problem.
  15. Calabonga
    Calabonga avatar
    29 posts
    Member since:
    Nov 2009

    Posted 06 Sep 2010 Link to this post

    Thank you very much!
    Your company is realy very good partner!
  16. Calabonga
    Calabonga avatar
    29 posts
    Member since:
    Nov 2009

    Posted 07 Sep 2010 Link to this post

    The problem is solved. Thanks!!!
    I setting up the control RadBusyIndicator's property DisplayAfter to default value (0.75 sec) and than RadGridView is now starting to SelectedItemChange. Early the value is 0.0 sec.
  17. Edu99
    Edu99 avatar
    4 posts
    Member since:
    Oct 2010

    Posted 29 Mar 2011 Link to this post

    Hi

     I'm using Silverlight,MVVM light, RIA and telerik 2010.3.

    I have a similar problem I have error with event SelectionChanged in RadGridView

    <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                        <cmd:EventToCommand PassEventArgsToCommand="True"
                                            Command="{Binding Path=SelectionChangedCommand}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>

Back to Top
DevCraft banner