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

[Solved] Issues with Customised Grouping in gridview

4 Answers 230 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Abhishek Chauhan
Top achievements
Rank 1
Abhishek Chauhan asked on 14 Oct 2009, 07:36 PM
Hi,

I have been facing some issues in grouping in gridview actually I have a multiselect combox having some of the fields (actually columns from grid) which are displayed in the grid (along with some other columns in grid). Now when some of the multiselect combobox field are checked the grid should be grouped accordingly and when unchecked the griview grouping should go off, now the following are the issues I'm facing

  1. When some  of the fields are checked in combobox the grid is grouped accordingly but actually grouping happens twice (i.e. the same group appears twice in the grid). now if we manuaaly remove this grouping (by clicking on the cross in the group headers) and check some or the other fields in combox again then the grouping happens as expected.
  2. When any of the fields in combox are unchecked the event is fired but the grouping in grid doesn't goes off.

i'm breaking my head on this issue for last one day.......please if anyone has ever come across such issue please do suggest the solution.
Below is my code\event that I am using-

Multiselect combobox-

 

<

 

 

 

 

telerikInput:RadComboBox FontFamily="Verdana" IsEditable="False" FontSize="10" x:Name="radcmbGroupMitigationsBy" HorizontalAlignment="Left" Width="135" Margin="40,45,0,0" VerticalAlignment="Top">

 

 

 

 

 

 

<telerikInput:RadComboBox Height="25" Width="0"/>

 

 

 

 

 

 

<telerikNavigation:RadTreeView x:Name="radtvGroupMitigationsBy" SelectionMode="Multiple" Checked="radtvGroupMitigationsBy_Checked" Unchecked="radtvGroupMitigationsBy_Unchecked">

 

 

 

 

 

 

</telerikNavigation:RadTreeView>

 

 

 

 

 

 

</telerikInput:RadComboBox>

Events-

 

private

 

void radtvGroupMitigationsBy_Checked(object sender, Telerik.Windows.RadRoutedEventArgs e)

 

{

 

 

 

 

var radtvItem = e.OriginalSource as RadTreeViewItem;

 

 

 

 

 

GroupDescriptor groupCriteria = new GroupDescriptor();

 

groupCriteria.Member = radtvItem.ToString();

groupCriteria.SortDirection =

 

 

 

ListSortDirection.Ascending;

 

 

 

 

 

this.rdgMitigationEvents.GroupDescriptors.Add(groupCriteria);

 

}

 

 

 

 

private void radtvGroupMitigationsBy_Unchecked(object sender, Telerik.Windows.RadRoutedEventArgs e)

 

{

 

 

 

 

var currentItem = e.OriginalSource as RadTreeViewItem;

 

 

 

 

 

GroupDescriptor groupCriteria = new GroupDescriptor();

 

groupCriteria.Member = currentItem.ToString();

 

 

 

 

this.rdgMitigationEvents.GroupDescriptors.Remove(groupCriteria);

 

}


Besides this I am not sure in which event to uncheck the combobox checked items if the user removes the grouping manually ie by clicking on the cross in grioup header in grouping panel above the grid.
I am using Silverlight 3.0.40723.0 and telerik radcontrols for Silverlight version 2009.2.812.1030
Please, please help me to fix this soon.

Thanks in Advance,
Abhishek Chauhan

 

 

 

 

 

 

 

 

 

 

4 Answers, 1 is accepted

Sort by
0
Abhishek Chauhan
Top achievements
Rank 1
answered on 15 Oct 2009, 07:11 AM
Please pick this thread and help me out.

Thanks In Advance,
Abhishek Chauhan
0
Rossen Hristov
Telerik team
answered on 16 Oct 2009, 02:28 PM
Hi Abhishek Chauhan,

This does not make any sense:

GroupDescriptor groupCriteria = new GroupDescriptor();

groupCriteria.Member = currentItem.ToString();

this.rdgMitigationEvents.GroupDescriptors.Remove(groupCriteria);

You are creating a brand new object and then you are trying to remove it from a collection it has never been added to. This will never work for sure.

You should create your descriptors only once, cache them and use them from there on. You will be simply adding and removing them from the grid's collection based on what check was checked.

Here is how you can do this:

<UserControl x:Class="TicketID_250485_ProgrammaticGrouping.MainPage"
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <StackPanel>
            <TextBlock FontSize="20" Margin="2">Pseudo-combo</TextBlock>
            <CheckBox Content="Name"
                      Margin="2"
                      Checked="OnCheckBoxChecked"
                      Unchecked="OnCheckBoxUnchecked"></CheckBox>
            <CheckBox Content="Number"
                      Margin="2"
                      Checked="OnCheckBoxChecked"
                      Unchecked="OnCheckBoxUnchecked"></CheckBox>
            <CheckBox Content="Position"
                      Margin="2"
                      Checked="OnCheckBoxChecked"
                      Unchecked="OnCheckBoxUnchecked"></CheckBox>
            <CheckBox Content="Country"
                      Margin="2"
                      Checked="OnCheckBoxChecked"
                      Unchecked="OnCheckBoxUnchecked"></CheckBox>
        </StackPanel>
        <telerik:RadGridView Name="playersGrid"
                             Grid.Row="1"
                             Margin="10"
                             AutoGenerateColumns="False"
                             ColumnsWidthMode="Auto"
                             AutoExpandGroups="True"
                             ShowGroupPanel="False">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="Name"
                                            DataMemberBinding="{Binding Name}"/>
                <telerik:GridViewDataColumn Header="Number"
                                            DataMemberBinding="{Binding Number}"/>
                <telerik:GridViewDataColumn Header="Position"
                                            DataMemberBinding="{Binding Position}"/>
                <telerik:GridViewDataColumn Header="Country"
                                            DataMemberBinding="{Binding Country}"/>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>
</UserControl>

And the code-behind is pretty simple as well:

using System.Collections.Generic;
using System.Windows.Controls;
using Telerik.Windows.Data;
 
namespace TicketID_250485_ProgrammaticGrouping
{
    public partial class MainPage : UserControl
    {
        readonly Dictionary<string, GroupDescriptor> groupDescriptors = new Dictionary<string, GroupDescriptor>();
         
        public MainPage()
        {
            InitializeComponent();
 
            this.groupDescriptors["Name"] = new GroupDescriptor { Member = "Name"};
            this.groupDescriptors["Number"] = new GroupDescriptor { Member = "Number" };
            this.groupDescriptors["Position"] = new GroupDescriptor { Member = "Position" };
            this.groupDescriptors["Country"] = new GroupDescriptor { Member = "Country" };
 
            this.playersGrid.ItemsSource = Club.GetPlayers();
        }
 
        private void OnCheckBoxChecked(object sender, System.Windows.RoutedEventArgs e)
        {
            this.PerformGrouping(true, ((CheckBox) sender).Content.ToString());
        }
 
        private void OnCheckBoxUnchecked(object sender, System.Windows.RoutedEventArgs e)
        {
            this.PerformGrouping(false, ((CheckBox)sender).Content.ToString());
        }
         
        private void PerformGrouping(bool group, string fieldName)
        {
            var gd = this.groupDescriptors[fieldName];
            if (group)
            {
                if (!this.playersGrid.GroupDescriptors.Contains(gd))
                {
                    this.playersGrid.GroupDescriptors.Add(gd);
                }
            }
            else
            {
                if (this.playersGrid.GroupDescriptors.Contains(gd))
                {
                    this.playersGrid.GroupDescriptors.Remove(gd);
                }
            }
        }
 
    }
}

I have prepared a small example that demonstrates how to do this. Please, examine it carefully.

Sincerely yours,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Abhishek Chauhan
Top achievements
Rank 1
answered on 18 Oct 2009, 11:57 PM
Hi Ross,

Thanks a lot for pointing out the mistake, actually I'm new to Silverlight and I was just following whatever I understood by going through various posts and blogs on net.
I think that the way I was adding the group criteria member was correct but while removing them I was following the wrong approach.
With the help of your suggestion I am able to implement the grouping but I am still facing the following issues-

1.  When some  of the fields are checked in combobox the grid is grouped accordingly but actually grouping happens twice   (i.e. the same group appears twice in the grid).  

2. When more than one checkboxes are checked the the groping happens as expected but the group panel (the group panel above the grid) still displays the field corresponding to the first checkbox only.

Again, thanks a lot for your help.

Thanks & Regards,
Abhishek Chauhan
0
Rossen Hristov
Telerik team
answered on 19 Oct 2009, 09:31 AM
Hi Abhishek Chauhan,

I have tried to reproduce the issues that you have described but I could not. Here is what I did:

Can you please tell me what steps do I need to perform on my sample project in order to reproduce the issues you are faced with. I am looking forward to hearing from you.

By the way make sure that your custom combo is not calling things twice which might be the cause of this "double" grouping.

Kind regards,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Abhishek Chauhan
Top achievements
Rank 1
Answers by
Abhishek Chauhan
Top achievements
Rank 1
Rossen Hristov
Telerik team
Share this question
or