How to display a mulit level hierarchy with a grid or treegrid
Hello,
I've got a nested data model which I want to be displayed in one Grid or TreeGrid. How is this best done?
public class Country : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _name;
private ObservableCollection<League> _leagues = new ObservableCollection<League>();
public string CountryName
{
get => _name;
set
{
_name = value;
OnPropertyChanged("CountryName");
}
}
public ObservableCollection<League> Leagues
{
get => _leagues;
set
{
_leagues = value;
OnPropertyChanged("Leagues");
}
}
private void OnPropertyChanged(String name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public class League : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _name;
private ObservableCollection<Match> _matches = new ObservableCollection<Match>();
public string LeagueName
{
get => _name;
set
{
_name = value;
OnPropertyChanged("LeagueName");
}
}
public ObservableCollection<Match> Matches
{
get => _matches;
set
{
_matches = value;
OnPropertyChanged("Matches");
}
}
private void OnPropertyChanged(String name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public class Market : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _name;
private double _odds;
public string MarketName
{
get => _name;
set
{
_name = value;
OnPropertyChanged("MarketName");
}
}
public double Odds
{
get => _odds;
set
{
_odds = value;
OnPropertyChanged("Odds");
}
}
private void OnPropertyChanged(String name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public class Match : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _name;
private ObservableCollection<Market> _markets = new ObservableCollection<Market>();
public string MatchName
{
get => _name;
set
{
_name = value;
OnPropertyChanged("MatchName");
}
}
public ObservableCollection<Market> Markets
{
get => _markets;
set
{
_markets = value;
OnPropertyChanged("Markets");
}
}
private void OnPropertyChanged(String name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
I've got a nested data model which I want to be displayed in one Grid or TreeGrid. How is this best done?
public class Country : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _name;
private ObservableCollection<League> _leagues = new ObservableCollection<League>();
public string CountryName
{
get => _name;
set
{
_name = value;
OnPropertyChanged("CountryName");
}
}
public ObservableCollection<League> Leagues
{
get => _leagues;
set
{
_leagues = value;
OnPropertyChanged("Leagues");
}
}
private void OnPropertyChanged(String name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public class League : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _name;
private ObservableCollection<Match> _matches = new ObservableCollection<Match>();
public string LeagueName
{
get => _name;
set
{
_name = value;
OnPropertyChanged("LeagueName");
}
}
public ObservableCollection<Match> Matches
{
get => _matches;
set
{
_matches = value;
OnPropertyChanged("Matches");
}
}
private void OnPropertyChanged(String name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public class Market : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _name;
private double _odds;
public string MarketName
{
get => _name;
set
{
_name = value;
OnPropertyChanged("MarketName");
}
}
public double Odds
{
get => _odds;
set
{
_odds = value;
OnPropertyChanged("Odds");
}
}
private void OnPropertyChanged(String name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public class Match : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _name;
private ObservableCollection<Market> _markets = new ObservableCollection<Market>();
public string MatchName
{
get => _name;
set
{
_name = value;
OnPropertyChanged("MatchName");
}
}
public ObservableCollection<Market> Markets
{
get => _markets;
set
{
_markets = value;
OnPropertyChanged("Markets");
}
}
private void OnPropertyChanged(String name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
SIGN IN To post a reply.
1 Reply
GT
Gnanasownthari Thirugnanam
Syncfusion Team
December 22, 2017 09:26 AM UTC
Hi SXTrader,
Analyzing your model, we found that you are using different types in different level. So, we suggest you to use SfDataGrid. SfTreeGrid can be used for self -relational data and same type of data used in all levels.
Please refer the below UG and attached sample for more details about DetailsViewDataGrid.
Sample link:
Regards,
Gnanasownthari T.
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
SX SXTrader
- Dec 21, 2017 03:37 PM UTC
- Dec 22, 2017 09:26 AM UTC