Hello Again...
I want to be able to hide a Group in the Group By.
I am binding the grid to a custom business object. For example:
class PermissionBinding
{
public string PermissionName { get; set; }
public string PermissionGroup { get; set; }
}
And the data in a BindingList<PermissionBinding> (#id, Permission Name, Permission Group) has:
#0: Create, Group 1
#1: Edit, Group 1
#2: View, Group 1
#3: Delete, Group 1
#4: Create, Group 2
#5: Edit, Group 2
#6: View, Group 2
#7: Delete, Group 2
... and so on.
So I bind the list to the grid via a BindingSource (all set up via the designer). But I create my list and set it to the binding source using:
_permissions = CreatePermissionBinding();
this.permissionBindingBindingSource.DataSource = _permissions;
I use Custom Grouping to group the rows under each Permission group nicely using the following:
Field Members (used to order the Groups and format the group name)
private const string GroupSortFormat = "{0:D4}. {1}|{1}";
private Dictionary<string, int> _groupOrder = new Dictionary<string, int>()
{
{ "Group 1", 1 },
{ "Group 2", 2 },
{ "Group 3", 3 },
};
Form Constructor
this.PermissionGridView.CustomGrouping += PermissionGridView_CustomGrouping;
this.PermissionGridView.GroupSummaryEvaluate += PermissionGridView_GroupSummaryEvaluate;
this.PermissionGridView.EnableCustomGrouping = true;
this.PermissionGridView.GroupDescriptors.Add(new Telerik.WinControls.Data.GroupDescriptor("PermissionGroup"));
Event Handlers
private void PermissionGridView_GroupSummaryEvaluate(object sender, Telerik.WinControls.UI.GroupSummaryEvaluationEventArgs e)
{
if (e.Value == null)
{
e.FormatString = e.Group.Key.ToString().Split('|')[1]; // strip out the order from the format string to show the group name
}
}
private void PermissionGridView_CustomGrouping(object sender, Telerik.WinControls.UI.GridViewCustomGroupingEventArgs e)
{
var obj = (PermissionBinding)e.Row.DataBoundItem;
e.GroupKey = string.Format(GroupSortFormat, _groupOrder[obj.PermissionGroup], obj.PermissionGroup); // make sure group is ordrered via string format
}
Now suppose I want to hide Group 2. Can I do it?
I have tried the following which only hides the rows in a group - it still shows the grouping Group 2:
foreach (var row in this.PermissionGridView.Rows)
{
row.IsVisible = groups.Contains((row.DataBoundItem as PermissionBinding).PermissionGroup) ? true : false;
}
I have successfully done it by removing the groups from the binding source BindingList<PermissionBinding>. But I see this as a view/filter on the data - suppose this is triggered by a user clicking a button. I really don't want to create the data source each time as it is populated through the database. Although it is not a major issue. I could maintain 2 lists - one main list and one filtered. But I was wondering if there was something in the Grid I had obviously missed to do this.
NOTE: Telerik is seriously kicking a competitors product into touch the more I do with it ;)!
Thanks,
Andez
I want to be able to hide a Group in the Group By.
I am binding the grid to a custom business object. For example:
class PermissionBinding
{
public string PermissionName { get; set; }
public string PermissionGroup { get; set; }
}
And the data in a BindingList<PermissionBinding> (#id, Permission Name, Permission Group) has:
#0: Create, Group 1
#1: Edit, Group 1
#2: View, Group 1
#3: Delete, Group 1
#4: Create, Group 2
#5: Edit, Group 2
#6: View, Group 2
#7: Delete, Group 2
... and so on.
So I bind the list to the grid via a BindingSource (all set up via the designer). But I create my list and set it to the binding source using:
_permissions = CreatePermissionBinding();
this.permissionBindingBindingSource.DataSource = _permissions;
I use Custom Grouping to group the rows under each Permission group nicely using the following:
Field Members (used to order the Groups and format the group name)
private const string GroupSortFormat = "{0:D4}. {1}|{1}";
private Dictionary<string, int> _groupOrder = new Dictionary<string, int>()
{
{ "Group 1", 1 },
{ "Group 2", 2 },
{ "Group 3", 3 },
};
Form Constructor
this.PermissionGridView.CustomGrouping += PermissionGridView_CustomGrouping;
this.PermissionGridView.GroupSummaryEvaluate += PermissionGridView_GroupSummaryEvaluate;
this.PermissionGridView.EnableCustomGrouping = true;
this.PermissionGridView.GroupDescriptors.Add(new Telerik.WinControls.Data.GroupDescriptor("PermissionGroup"));
Event Handlers
private void PermissionGridView_GroupSummaryEvaluate(object sender, Telerik.WinControls.UI.GroupSummaryEvaluationEventArgs e)
{
if (e.Value == null)
{
e.FormatString = e.Group.Key.ToString().Split('|')[1]; // strip out the order from the format string to show the group name
}
}
private void PermissionGridView_CustomGrouping(object sender, Telerik.WinControls.UI.GridViewCustomGroupingEventArgs e)
{
var obj = (PermissionBinding)e.Row.DataBoundItem;
e.GroupKey = string.Format(GroupSortFormat, _groupOrder[obj.PermissionGroup], obj.PermissionGroup); // make sure group is ordrered via string format
}
Now suppose I want to hide Group 2. Can I do it?
I have tried the following which only hides the rows in a group - it still shows the grouping Group 2:
foreach (var row in this.PermissionGridView.Rows)
{
row.IsVisible = groups.Contains((row.DataBoundItem as PermissionBinding).PermissionGroup) ? true : false;
}
I have successfully done it by removing the groups from the binding source BindingList<PermissionBinding>. But I see this as a view/filter on the data - suppose this is triggered by a user clicking a button. I really don't want to create the data source each time as it is populated through the database. Although it is not a major issue. I could maintain 2 lists - one main list and one filtered. But I was wondering if there was something in the Grid I had obviously missed to do this.
NOTE: Telerik is seriously kicking a competitors product into touch the more I do with it ;)!
Thanks,
Andez