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

Grouping objects in RadGridView

1 Answer 44 Views
GridView
This is a migrated thread and some comments may be shown as answers.
DTA
Top achievements
Rank 1
DTA asked on 28 May 2014, 01:22 PM
We are having a problem grouping objects in the RadGridView.
For example ,one of the properties of our objects is named:Changed.
When the application is loaded,the RadGridView and GridViewScrollbar behave well.
After grouping ,if the value of the property(Changed) changes in a specific object,then it should move to the appropriate group.
Unfortuntely,this does not happen.
To solve this bug ,we tried to manually sort oir regroup.
This solved the current bug,but created another bug.
The GridViewScrollbar of the grid moves up suddenly and does not stay in its original position.
The vertical offset =0.
In addition , when we return to the initial state (cancel the grouping ),the GridViewScrollbar still changes its position.
The objects in the items source update all the time.
In addition , we raise a property changed event on the collection bound to the item source.

How is this accomplished?

thanks in advance for your help.

public class MyDataContext
    {
        readonly string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        Random rnd ;

ObservableCollection<StockData> _source;
ObservableCollection<StockData> Source
        {
            get
            {
               if (_source == null)
                {
                       rnd=new Random();

                       _source = new ObservableCollection<StockData>(from i in Enumerable.Range(0, 20) select CreateStockData());

                       DispatcherTimer timer = new DispatcherTimer() 
                                   { 
                                         Interval = TimeSpan.FromSeconds(10),
                                          timer.Tick += new EventHandler(timer_Tick),
                                         timer.Start()
                                     };

                     return this.source;
            }
        }

        void timer_Tick(object sender,EventArgs e)
        { 
                switch(source [0].Change)
                {
                          case 0 :
                                source [0] .Change = 1 ;
                                 break;
                           case 1 :
                                 source [0] .Change = 0 ;
                                 break;
                 }
             SortCollection() ; 
        }

        private StockData CreateStockData()
        {
            StockData item = new StockData();
            item.Name = String.Format("{0}{1}{2}{3}", this.letters[this.rnd.Next(0, this.letters.Count())], this.letters[this.rnd.Next(0, this.letters.Count())],
                                                              this.letters[this.rnd.Next(0, this.letters.Count())], this.letters[this.rnd.Next(0, this.letters.Count())]);
            item.LastUpdate = DateTime.Now;
            item.Change = rnd.Next(0,2);
            return item;
        }

        QueryableCollectionView _data;
        public QueryableCollectionView Data
        {
            get
            {
                 if (this.data == null)
                {
                      _data = new QueryableCollectionView(Source);
                      _data.SortDescriptors.Add(new SortDescriptor()
                      {
                               Member = "Name",
                               SortDirection = System.ComponentModel.ListSortDirection.Descending
                      });

                    _data.SortDescriptors.Add(new SortDescriptor()
                   { 
                              Member = "Name",
                             SorttDirection = System.ComponentModel.ListSortDirection.Ascending
                   });
                }

               return _data;
            }
        }

        private void SortCollection()
        {
                   _data.SortDescriptors.Add(new SortDescriptor()
                         {
                               Member = "Name",
                               SortDirection = System.ComponentModel.ListSortDirection.Descending
                         });

                    _data.SortDescriptors.Add(new SortDescriptor()
                          { 
                              Member = "Name",
                             SorttDirection = System.ComponentModel.ListSortDirection.Ascending
                          });
        }  

    Public class StockData
    {
        public string Name{get;set;}
        public int Change{get;set;}
        public DateTime LastUpdate{get;set;}
     }
}

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 02 Jun 2014, 08:46 AM
Hi,

I have answered in the other forum thread you have opened on the same topic.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
DTA
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or