We are having 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 the 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 or regroup.
This bug solved the currnt,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 it's position.
The objects in the item 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;}
}
}
For example ,one of the properties of our objects is named: Changed.
When the application is loaded, the RadGridView and the 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 or regroup.
This bug solved the currnt,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 it's position.
The objects in the item 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;}
}
}