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

How to add ColumnGroup in RadGridView.ColumnGroups at run time (from code behind)

8 Answers 681 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Laxman
Top achievements
Rank 1
Laxman asked on 04 Sep 2012, 07:03 AM

The following XAML shows that I want to create ColumnGroups at run time same as like XAML code (which is following) based on business requirement which is not constant. How to do that in code behind I am unable to add. Please send me the code snippet.
=====================================================================================================

<Tele:RadGridView Name="RgvViewWorkforcePlan" GridLinesVisibility="Both" IsReadOnly="True" AutoGenerateColumns="False" VerticalAlignment="Stretch"
                              CanUserFreezeColumns="False" ShowGroupPanel="true" RowIndicatorVisibility="Collapsed" Width="Auto"
                              ScrollViewer.VerticalScrollBarVisibility="auto"  ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="auto" SnapsToDevicePixels="False" VerticalContentAlignment="Top"
                              ItemsSource="{Binding TempGridData,Mode=OneWay}" CanUserResizeColumns="False"   SelectionMode="Single" SelectionUnit="FullRow" SelectedItem="{Binding SelectedGridItem,Mode=TwoWay}"
                              Background="#EAF3FC" >
                <!--It creates a column group in which we can merge column headers as needed-->
                <!--1st group Header for the 1st month -->
                    <Tele:RadGridView.ColumnGroups>
                        <Tele:GridViewColumnGroup Name="MonthName1"  >
                            <Tele:GridViewColumnGroup.HeaderTemplate>
                                <DataTemplate>
                                    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="#EAF3FC" Name="grdcolumnHeader1"  >
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="23"></RowDefinition>
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"></ColumnDefinition>
                                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                                        </Grid.ColumnDefinitions>
                                        <Label  Name="lblMonthName1"  Grid.Row="0" Grid.Column="0" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalAlignment="Stretch"  Padding="0" Margin="0,2,0,0" FontWeight="DemiBold"
                                              Content="{Binding  Path=DataContext.MonthName1,RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Tele:GridViewDataControl}}}" ></Label>
                                         <StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Stretch" Width="Auto" Name="sPanel1"
                                                     Visibility="{Binding Path=DataContext.SPanel1,RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Tele:GridViewDataControl}}}">
                                            <Button Name="btnFirst" HorizontalAlignment="Center" VerticalAlignment="Center" Content="&lt;&lt;"/>
                                            <Button Name="btnPrevious" HorizontalAlignment="Center" VerticalAlignment="Center" Content="&lt;"/>
                                            <Button Name="btnNext" HorizontalAlignment="Center" VerticalAlignment="Center" Content="&gt;" Click="btnNext_Click"/>
                                            <Button Name="btnLast" HorizontalAlignment="Center" VerticalAlignment="Center" Content="&gt;&gt;"/>
                                        </StackPanel>
                                    </Grid>
                                </DataTemplate>
                            </Tele:GridViewColumnGroup.HeaderTemplate>
                        </Tele:GridViewColumnGroup>
                         </Tele:RadGridView.ColumnGroups>

Thanks

Laxman.

8 Answers, 1 is accepted

Sort by
0
Accepted
Pavel Pavlov
Telerik team
answered on 06 Sep 2012, 02:40 PM
Hi,

To create a new group programmatically use :

GridViewColumnGroup columnGroup = new GridViewColumnGroup();
columnGroup.Name = "XXXXXX"; // replace the XXXX with a name of your choice...

To add child groups to a column group use :
columnGroup.ChildGroups.Add(.....);

To tell a column it belongs to a given group use :

this.RadGridView1.Columns[0].ColumnGroupName = "XXXXXXX";

To add a programmatically created group to RadGridView use :
this.RadGridView1.ColumnGroups.Add(columnGroup);

All the best,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Laxman
Top achievements
Rank 1
answered on 07 Sep 2012, 01:45 PM
Hi Support Team,

Thanks a lot.

laxman
0
Anil Kumar
Top achievements
Rank 1
answered on 28 Sep 2012, 06:17 AM
Hi Pavel,

i can able to create a telerik radgridview control, in addition to that i also need to collapse and expand the entire columngroup. will it be possible with this control or is there any other way.

Help me on this issue.

Thanks & Regards
Anil
0
Vlad
Telerik team
answered on 28 Sep 2012, 06:37 AM
Hi,

 You cannot collapse and expand column groups in RadGridView. If you want such functionality you may need to check our PivotGrid:
http://demos.telerik.com/silverlight/#PivotGrid/Layouts

Greetings,
Vlad
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Anil Kumar
Top achievements
Rank 1
answered on 28 Sep 2012, 07:43 AM
Hi Telerik Team,

I Think PIVOTGRID is not allowing values other than number.

i want to display some string columns also in it. is it possible.

Thanks

Anil
0
Rosen Vladimirov
Telerik team
answered on 28 Sep 2012, 11:33 AM
Hi Anil,

The PivotGrid is used for aggregating data. You can apply different aggregate functions (sum, count, etc.) and string formats on the value (for example setting currency, decimals, etc.) but it is not designed to work with string data.

May we receive more information on your scenario and exactly what you want to expand/collapse?

All the best,
Rosen Vladimirov
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Anil Kumar
Top achievements
Rank 1
answered on 28 Sep 2012, 01:22 PM
Hi Telerik,

Thank you for Your Prompt Response.

my requirement looks like:-

Run Count

Average Run Time (sec)

% Timeouts

Id

Name

Page

Parameters

Run1

Run2

Run3

Run4

Run5

Run1

Run2

Run3

Run4

Run5

Run1

Run2

Run3

Run4

Run5

1418

ABC1 XYZ1 ASDSDA

4

3

12

0

0

3.34

1.07

1.9

0

0

0

0

0

0

0

1420

ABC2
XYZ2 DSASDAS

2

14

13

0

0

5.8

0.74

1.85

0

0

0

0

0

0

0

1419

ABC3

XYZ3

ASDASD

0

2

6

0

0

0

1.72

2.0

0

0

0

0

0

0

0

1421

 

ABC4

XYZ4

ADASDASD

3

12

26

0

0

2.12

2.0

3.21

0

0

0

0

0

0

0

 

In the above Grid Run Count is ColumnGroup i want this ColumnGroup to be collapsed and Expanded. So that it will be easy to check data without scrolling.


Thanks
Anil
0
Rosen Vladimirov
Telerik team
answered on 01 Oct 2012, 07:55 PM
Hi Anil,

Thanks for the explanation. We have tried this scenario with our PivotGrid and with Excel's Pivot but several issues raised:
 - the data in the first four columns - the Pivot itself is designed for Aggregating Data (i.e. sum, average, etc. of numeric values). We have found a workaround for this problem - we merged the first four columns in one column (we called it "build") and we set it to be displayed as rows in our PivotGrid
 - collapse of the RunCount column group is NOT possible. Such collapse is not available in the Excel's Pivot as well and we have not consider adding such functionality to our RadPivotGrid.

We have set a simple data in the attached Excel file and we have created a PivotGrid there based on this sample data. Please take a look at it and comment if this is acceptable for your scenario. Note that with our RadPivotGrid we'll be able to create the same Pivot Table as it is in the Excel file, but this is the most customized possible solution in the moment. If you want to apply something else (for example the mentioned collapse or using the first four columns separately) most probably we won't be able to do it. The other problem with such solution is the data that will be populated. If it is not in the format used in the Excel file, it will be very difficult (most probably impossible) to implement the scenario.

Looking forward to hearing from you.

Greetings,
Rosen Vladimirov
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

Tags
General Discussions
Asked by
Laxman
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Laxman
Top achievements
Rank 1
Anil Kumar
Top achievements
Rank 1
Vlad
Telerik team
Rosen Vladimirov
Telerik team
Share this question
or