Hi,
I have a problem with grouping data in RadGridView. I set IList as dataSource to RadGridView.
IList is a list of objects some class Product. Class Product has property Category which is a class with some fields too.
How can I set by what field of class Gategory group the data, when I grouping by Category column in Poduct ?
Any help would be appreciated!
Regards!
I have a problem with grouping data in RadGridView. I set IList as dataSource to RadGridView.
IList is a list of objects some class Product. Class Product has property Category which is a class with some fields too.
How can I set by what field of class Gategory group the data, when I grouping by Category column in Poduct ?
Any help would be appreciated!
Regards!
14 Answers, 1 is accepted
0

Richard Slade
Top achievements
Rank 2
answered on 15 Dec 2010, 11:10 AM
Hi Pavel,
Have a look at the docs at this link in order to acheive grouping. The PropertyName of the GroupDescriptor needs to be the ColumnName.
E.g.
Hope that helps, but let me know if you need more information
Richard
Have a look at the docs at this link in order to acheive grouping. The PropertyName of the GroupDescriptor needs to be the ColumnName.
E.g.
descriptor1.GroupNames.Add(
"ColumnName"
, ListSortDirection.Ascending)
Hope that helps, but let me know if you need more information
Richard
0

Richard Slade
Top achievements
Rank 2
answered on 16 Dec 2010, 01:14 PM
Hello,
How did you get on with this? If it helped, please mark as answer. If you need more help, just let me know
Regards,
Richard
How did you get on with this? If it helped, please mark as answer. If you need more help, just let me know
Regards,
Richard
0

Pavel
Top achievements
Rank 1
answered on 16 Dec 2010, 03:15 PM
Richard , thank you very much for your quick responses.
I tried this also but unfortunately, I could not solve the problem.
I can not understand how can I select necessary field in class Category to group Products.
Below is the code of my problem
I tried this also but unfortunately, I could not solve the problem.
I can not understand how can I select necessary field in class Category to group Products.
Below is the code of my problem
01.
public
partial
class
Form1 : Form
02.
{
03.
public
Form1()
04.
{
05.
InitializeComponent();
06.
radGridView1.DataSource = InitList();
07.
}
08.
09.
private
List<Product> InitList()
10.
{
11.
List<Product> list =
new
List<Product>();
12.
var category1 =
new
Category() {Id = 1, CategoryName =
"Category1"
};
13.
var category2 =
new
Category() {Id = 2, CategoryName =
"Category2"
};
14.
list.Add(
new
Product()
15.
{
16.
Id = 1,
17.
Name =
"Product1"
,
18.
ProductCategory = category1
19.
});
20.
list.Add(
new
Product()
21.
{
22.
Id = 2,
23.
Name =
"Product2"
,
24.
ProductCategory = category2
25.
});
26.
list.Add(
new
Product()
27.
{
28.
Id = 3,
29.
Name =
"Product3"
,
30.
ProductCategory = category1
31.
});
32.
return
list;
33.
}
34.
35.
class
Product
36.
{
37.
public
int
Id {
get
;
set
; }
38.
public
string
Name {
get
;
set
; }
39.
public
Category ProductCategory {
get
;
set
; }
40.
}
41.
42.
class
Category
43.
{
44.
public
int
Id {
get
;
set
; }
45.
public
string
CategoryName {
get
;
set
; }
46.
47.
public
override
string
ToString()
48.
{
49.
return
CategoryName;
50.
}
51.
}
52.
}
When I group Product by column Category, all Products are in Category1 and Category2 is missing
0

Richard Slade
Top achievements
Rank 2
answered on 16 Dec 2010, 03:26 PM
hello Pavel,
Please try this. this is grouped by "Name", the name of the column for the product.
let me know if that helps
Richard
Please try this. this is grouped by "Name", the name of the column for the product.
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
radGridView1.DataSource = InitList();
radGridView1.EnableGrouping =
true
;
}
private
void
Form1_Load(
object
sender, EventArgs e)
{
GroupDescriptor descriptor =
new
GroupDescriptor();
descriptor.GroupNames.Add(
"Name"
, ListSortDirection.Ascending);
this
.radGridView1.GroupDescriptors.Add(descriptor);
}
private
List<Product> InitList()
{
List<Product> list =
new
List<Product>();
var category1 =
new
Category() {Id = 1, CategoryName =
"Category1"
};
var category2 =
new
Category() {Id = 2, CategoryName =
"Category2"
};
list.Add(
new
Product()
{
Id = 1,
Name =
"Product1"
,
ProductCategory = category1
});
list.Add(
new
Product()
{
Id = 2,
Name =
"Product2"
,
ProductCategory = category2
});
list.Add(
new
Product()
{
Id = 3,
Name =
"Product3"
,
ProductCategory = category1
});
return
list;
}
}
class
Product
{
public
int
Id {
get
;
set
; }
public
string
Name {
get
;
set
; }
public
Category ProductCategory {
get
;
set
; }
}
class
Category
{
public
int
Id {
get
;
set
; }
public
string
CategoryName {
get
;
set
; }
public
override
string
ToString()
{
return
CategoryName;
}
}
let me know if that helps
Richard
0

Richard Slade
Top achievements
Rank 2
answered on 17 Dec 2010, 11:05 AM
Hi Pavel,
Did this help?
Thanks
Richard
Did this help?
Thanks
Richard
0

Richard Slade
Top achievements
Rank 2
answered on 20 Dec 2010, 01:48 PM
Hello,
If this helped, please remember to mark as answer so others can find the solution too.
regards,
Richard
If this helped, please remember to mark as answer so others can find the solution too.
regards,
Richard
0

Pavel
Top achievements
Rank 1
answered on 28 Dec 2010, 09:11 AM
Sorry Richard, but it didn't help ! You didn't understand me correctly. In my task I need to group not by Name, but group by field Name of field Category.
0

Richard Slade
Top achievements
Rank 2
answered on 28 Dec 2010, 12:36 PM
Pavel,
As far as I jnow, you'll need to link it via the Category Id, not the object. Please see the exmaple
Hope that helps
Richard
As far as I jnow, you'll need to link it via the Category Id, not the object. Please see the exmaple
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
radGridView1.DataSource = InitList();
radGridView1.EnableGrouping =
true
;
RadControlSpyForm form =
new
RadControlSpyForm();
form.Show();
}
private
void
Form1_Load(
object
sender, EventArgs e)
{
GroupDescriptor descriptor =
new
GroupDescriptor();
descriptor.GroupNames.Add(
"ProductCategory"
, ListSortDirection.Ascending);
this
.radGridView1.GroupDescriptors.Add(descriptor);
}
private
List<Product> InitList()
{
List<Product> list =
new
List<Product>();
Category category1 =
new
Category() { Id = 1, CategoryName =
"Category1"
};
Category category2 =
new
Category() { Id = 2, CategoryName =
"Category2"
};
list.Add(
new
Product()
{
Id = 1,
Name =
"Product1"
,
ProductCategory = 1
});
list.Add(
new
Product()
{
Id = 2,
Name =
"Product2"
,
ProductCategory = 2
});
list.Add(
new
Product()
{
Id = 3,
Name =
"Product3"
,
ProductCategory = 1
});
return
list;
}
}
class
Product
{
public
int
Id {
get
;
set
; }
public
string
Name {
get
;
set
; }
public
int
ProductCategory {
get
;
set
; }
}
class
Category
{
public
int
Id {
get
;
set
; }
public
string
CategoryName {
get
;
set
; }
public
override
string
ToString()
{
return
CategoryName;
}
}
Hope that helps
Richard
0

Pavel
Top achievements
Rank 1
answered on 28 Dec 2010, 04:36 PM
Hi, Richard !
If I understand correctly - you propose to replace the type of property from Category to Int and group by it?
I understand, that i can group by value-type.
Then, i must change my model only for display it in the grid?
It is possible to group by instance of custom type?
0

Richard Slade
Top achievements
Rank 2
answered on 28 Dec 2010, 07:46 PM
Hi,
As far as I know, no. you must group by a value type.
Hope that helps
Richard
As far as I know, no. you must group by a value type.
Hope that helps
Richard
0

Alexander
Top achievements
Rank 1
answered on 29 Dec 2010, 10:57 AM
Hi!
It is imporant feature, that i can group by instance of custom class.
Overriding "Equals" of custom class doesn't work.
How grouping works inside? It is hard-coded switch with cases for each value type? :)
I hope it is not true, and "grouping engine" are more flexible. I'm sure, that set by which value-field of custom class instance do grouping, is it possible, because developers simply couldn't forget this possibility.
Maybe, someone, who are closer to development of this control can give answer?
Thanks for attention!
It is imporant feature, that i can group by instance of custom class.
Overriding "Equals" of custom class doesn't work.
How grouping works inside? It is hard-coded switch with cases for each value type? :)
I hope it is not true, and "grouping engine" are more flexible. I'm sure, that set by which value-field of custom class instance do grouping, is it possible, because developers simply couldn't forget this possibility.
Maybe, someone, who are closer to development of this control can give answer?
Thanks for attention!
0
Accepted
Hello Pavel,
You can implement this scenario by using sub-properties binding. Bind the Category column to the desired property of the Category object. This will allow you to apply grouping on this column, Please check the online help for sub-property binding and our Data manipulation example in our demo application.
I hope this was helpful.
Richard thank you for your comments and assistance.
Greetings,
Julian Benkov
the Telerik team
You can implement this scenario by using sub-properties binding. Bind the Category column to the desired property of the Category object. This will allow you to apply grouping on this column, Please check the online help for sub-property binding and our Data manipulation example in our demo application.
I hope this was helpful.
Richard thank you for your comments and assistance.
Greetings,
Julian Benkov
the Telerik team
Check out the Q1 2011 Roadmap for Telerik Controls for Windows Forms.
0

Alexander
Top achievements
Rank 1
answered on 30 Dec 2010, 02:44 PM
Thanks, Julian Benkov, it is working.
Answer is simple. For group by Product.Category.Name, you need to set FieldName of column to "Category.Name" :)
Can i bind column text to one property and column value to another? Such as DisplayMember and ValueMember in ComboBox.
For example, i need display Category.Name as column text, but group by Category.Id.
Thanks!
Answer is simple. For group by Product.Category.Name, you need to set FieldName of column to "Category.Name" :)
Can i bind column text to one property and column value to another? Such as DisplayMember and ValueMember in ComboBox.
For example, i need display Category.Name as column text, but group by Category.Id.
Thanks!
0
Hi Pavel,
I hope this is helpful.
Kind regards,
Julian Benkov
the Telerik team
You can not implement this behavior using properties such as DisplayMember, ValueMember valid for combobox control and column. To support this functionality you can create two columns and bind them to 'Category.Id' and "Category.Name". You can make the 'Category.Id' column invisible and execute the grouping operation using GroupDescriptors API:
this
.radGridView1.Columns.Add(
"CategoryId"
,
"Category Id"
,
"Category.Id"
);
this
.radGridView1.Columns.Add(
"CategoryName"
,
"Category Name"
,
"Category.Name"
);
this
.radGridView1.Columns[
"CategoryId"
].IsVisible =
false
;
this
.radGridView1.GroupDescriptors.Expression =
"CategoryId"
;
I hope this is helpful.
Kind regards,
Julian Benkov
the Telerik team