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

How Can I Grouping by tags a RadGridView

1 Answer 175 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Riccardo
Top achievements
Rank 1
Riccardo asked on 11 Feb 2015, 09:40 AM
I have this class

public class myObject
  {
 
  public String Name { get; set; }
  public List<String> Tags{get;set;}
 
 
  }
this ViewModel
public class ViewModelMainWindow:ViewModel
  {
 
  System.ComponentModel.ICollectionView m_myListOfObject;
 
  public ICollectionView MyListOfObject
    {
    get { return m_myListOfObject; }
    set { m_myListOfObject = value; }
    }
 
 
 
  }
I initialize my App
public partial class App : Application
  {
  MainWindow m_ViewMainWindow;
  ViewModelMainWindow m_ViewModelMainWindows;
 
  List<myObject> m_myListOfObject;
 
  protected override void OnStartup(StartupEventArgs e)
    {
    Init();
    m_ViewMainWindow.Show();
    }
 
  void Init()
    {
    m_ViewMainWindow = new MainWindow();
    m_ViewModelMainWindows = new ViewModelMainWindow();
 
 
    PropertyGroupDescription groupDescriptionPorte = new PropertyGroupDescription("Tags");
 
    m_myListOfObject = new List<myObject>();
 
    m_myListOfObject.Add(new myObject());
 
    m_myListOfObject.Last().Name = "Element 1";
    m_myListOfObject.Last().Tags = new List<string>();
    m_myListOfObject.Last().Tags.Add("Tag 1");
    m_myListOfObject.Last().Tags.Add("Tag 2");
    m_myListOfObject.Add(new myObject());
 
    m_myListOfObject.Last().Name = "Element 2";
    m_myListOfObject.Last().Tags = new List<string>();
    m_myListOfObject.Last().Tags.Add("Tag 1");
    m_myListOfObject.Last().Tags.Add("Tag 3");
    m_myListOfObject.Add(new myObject());
 
 
    m_myListOfObject.Last().Name = "Element 3";
    m_myListOfObject.Last().Tags = new List<string>();
    m_myListOfObject.Last().Tags.Add("Tag 2");
    m_myListOfObject.Last().Tags.Add("Tag 4");
 
 
 
    m_ViewModelMainWindows.MyListOfObject = CollectionViewSource.GetDefaultView(m_myListOfObject);
 
    m_ViewModelMainWindows.MyListOfObject.GroupDescriptions.Add(groupDescriptionPorte);
 
    m_ViewMainWindow.DataContext = m_ViewModelMainWindows;
 
 
    }
  }

How can I view the groups by tags "Tag 1", "Tag 2", "Tag 3", "Tag 4" in a RadGridView?
In m_ViewModelMainWindows.MyListOfObject I have 4 groups, but in RadGridView of MainWindow I have 3 groups of list.

The MainWindow.xaml is
<Window
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" x:Class="grouping_by_tags.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="137*"/>
            <RowDefinition Height="183*"/>
        </Grid.RowDefinitions>
 
        <telerik:RadGridView HorizontalAlignment="Left" Height="320" VerticalAlignment="Top" Width="517" ItemsSource="{Binding MyListOfObject}" Grid.RowSpan="2"/>
 
 
    </Grid>
</Window>

Best regards

Riccardo

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 12 Feb 2015, 01:15 PM
Hello Riccardo,

As I get from your code, you are trying to group your objects by a collection property, which is not possible in RadGridView. A way to achieve the desired grouping behavior, is to define a separate property for each "Tag" in the business object.

In addition, I would recommend you to read our documentation on the RadGridView grouping functionality.

Best Regards,
Stefan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Riccardo
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or