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

[Solved] Dynamic Column ADD

4 Answers 305 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.
park
Top achievements
Rank 1
park asked on 13 Aug 2009, 06:19 AM
Hi!~
When Dynimic Column ADD, The following problems..

1. Static Column and new Dynimic is Unequal each other
2. cann`t try to Column Edit mode

Please, Help Me~ T.T


<UserControl x:Class="SilverRadDynamicColumn.Page" 
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 
    xmlns:gridView="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView" 
    xmlns:theme="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" 
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows" 
    Width="Auto" Height="600">  
    <Grid x:Name="LayoutRoot">  
 
        <Grid.Resources> 
            <theme:VistaTheme x:Key="Theme"/>  
 
            <ControlTemplate x:Key="GridViewGroupPanelTemplate" TargetType="gridView:GridViewGroupPanel">  
                <Grid> 
                    <vsm:VisualStateManager.VisualStateGroups> 
                        <vsm:VisualStateGroup x:Name="Grouping">  
                            <vsm:VisualState x:Name="NoGroups">  
                                <Storyboard> 
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="panelText" Storyboard.TargetProperty="Visibility">  
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>  
                                    </ObjectAnimationUsingKeyFrames> 
                                </Storyboard> 
                            </vsm:VisualState> 
                            <vsm:VisualState x:Name="HasGroups">  
                                <Storyboard> 
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="panelText" Storyboard.TargetProperty="Visibility">  
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed"/>  
                                    </ObjectAnimationUsingKeyFrames> 
                                </Storyboard> 
                            </vsm:VisualState> 
                        </vsm:VisualStateGroup> 
                    </vsm:VisualStateManager.VisualStateGroups> 
                    <Border Margin="{TemplateBinding Margin}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">  
 
                        <!--SETTING CUSTOM TEXT OF THE GROUP PANEL--> 
                        <TextBlock x:Name="panelText" HorizontalAlignment="Left" VerticalAlignment="Center" IsHitTestVisible="False" FontSize="{TemplateBinding FontSize}" FontStyle="{TemplateBinding FontStyle}" Foreground="{TemplateBinding Foreground}" Padding="{TemplateBinding Padding}" Text="그룹정렬을 원하는 필드명을 드래그해서 올려놓으세요(권고:3개이하) " /> 
 
                    </Border> 
                    <ItemsPresenter Margin="10,6,10,0"/>  
                </Grid> 
            </ControlTemplate> 
            <ItemsPanelTemplate x:Key="GridViewGroupPanelItemsPanelTemplate">  
                <StackPanel VerticalAlignment="Stretch" Orientation="Horizontal"/>  
            </ItemsPanelTemplate> 
            <Style x:Key="GridViewGroupPanelStyle" TargetType="gridView:GridViewGroupPanel">  
                <Setter Property="Template" Value="{StaticResource GridViewGroupPanelTemplate}"/>  
                <Setter Property="ItemsPanel" Value="{StaticResource GridViewGroupPanelItemsPanelTemplate}"/>  
 
                <!--GroupPanel Customization Propoerties (ALL GroupPanels)--> 
                <Setter Property="Margin" Value="0"/>  
                <Setter Property="Padding" Value="10,6,10,5"/>  
                <Setter Property="FontSize" Value="12"/>  
                <Setter Property="FontStyle" Value="Normal"/>  
 
            </Style> 
 
            <ControlTemplate x:Key="GridViewItemsControlTemplate" TargetType="gridView:GridViewItemsControl">  
                <Grid x:Name="HierrarchyBackground" Background="{TemplateBinding Background}">  
                    <Grid.ColumnDefinitions> 
                        <ColumnDefinition/> 
                        <ColumnDefinition x:Name="ScrollBarColumn" MinWidth="0" Width="0"/>  
                    </Grid.ColumnDefinitions> 
                    <Grid.RowDefinitions> 
                        <RowDefinition Height="Auto"/>  
                        <RowDefinition Height="Auto"/>  
                        <RowDefinition/> 
                        <RowDefinition x:Name="ScrollBarRow" Height="0" MinHeight="0"/>  
                    </Grid.RowDefinitions> 
                    <vsm:VisualStateManager.VisualStateGroups> 
                        <vsm:VisualStateGroup x:Name="ColumnHeadersVisibility">  
                            <vsm:VisualState x:Name="ColumnHeadersVisible">  
                                <Storyboard> 
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HeaderRow" Storyboard.TargetProperty="Visibility">  
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>  
                                    </ObjectAnimationUsingKeyFrames> 
                                </Storyboard> 
                            </vsm:VisualState> 
                            <vsm:VisualState x:Name="ColumnHeadersCollapsed">  
                                <Storyboard> 
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HeaderRow" Storyboard.TargetProperty="Visibility">  
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed"/>  
                                    </ObjectAnimationUsingKeyFrames> 
                                </Storyboard> 
                            </vsm:VisualState> 
                        </vsm:VisualStateGroup> 
                        <vsm:VisualStateGroup x:Name="GroupPanelVisibility">  
                            <vsm:VisualState x:Name="GroupPanelVisible">  
                                <Storyboard> 
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_GroupPanel" Storyboard.TargetProperty="Visibility">  
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>  
                                    </ObjectAnimationUsingKeyFrames> 
                                </Storyboard> 
                            </vsm:VisualState> 
                            <vsm:VisualState x:Name="GroupPanelCollapsed">  
                                <Storyboard> 
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_GroupPanel" Storyboard.TargetProperty="Visibility">  
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed"/>  
                                    </ObjectAnimationUsingKeyFrames> 
                                </Storyboard> 
                            </vsm:VisualState> 
                        </vsm:VisualStateGroup> 
                    </vsm:VisualStateManager.VisualStateGroups> 
                    <gridView:GridViewGroupPanel x:Name="PART_GroupPanel" MinHeight="{TemplateBinding MinHeight}" Background="{TemplateBinding GroupPanelBackground}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Foreground="{TemplateBinding GroupPanelForeground}" Grid.ColumnSpan="2" Grid.Row="0" theme:StyleManager.Theme="{StaticResource Theme}" Style="{StaticResource GridViewGroupPanelStyle}"/>  
                    <StackPanel Grid.Row="1">  
                        <gridView:GridViewHeaderRow x:Name="PART_HeaderRow" VerticalAlignment="Top" IndentLevel="{TemplateBinding GroupCount}" theme:StyleManager.Theme="{StaticResource Theme}"/>  
                        <gridView:GridViewNewRow x:Name="PART_AddNewRow" HorizontalAlignment="Left" VerticalAlignment="Bottom" Visibility="Collapsed" IndentLevel="{TemplateBinding GroupCount}" theme:StyleManager.Theme="{StaticResource Theme}"/>  
                    </StackPanel> 
                    <gridView:GridViewScrollViewer x:Name="PART_ItemsScrollViewer" Grid.ColumnSpan="2" Grid.Row="2" Grid.RowSpan="2" CanHorizontallyScroll="True" theme:StyleManager.Theme="{StaticResource Theme}">  
                        <gridView:GridViewVirtualizingPanel x:Name="PART_GridViewVirtualizingPanel" theme:StyleManager.Theme="{StaticResource Theme}"/>  
                    </gridView:GridViewScrollViewer> 
                    <gridView:ScrollPositionIndicator x:Name="PART_ScrollPositionIndicator" HorizontalAlignment="Right" Margin="0,0,28,0" IsHitTestVisible="False" Visibility="Collapsed" Grid.ColumnSpan="2" Grid.Row="2" theme:StyleManager.Theme="{StaticResource Theme}" IsScrolling="{TemplateBinding IsScrolling}"/>  
                    <Border x:Name="PART_FrozenColumnsPreview" HorizontalAlignment="Left" VerticalAlignment="Stretch" Width="6" Visibility="Collapsed" Grid.Row="1" Grid.RowSpan="4" Background="#33000000"/>  
                </Grid> 
            </ControlTemplate> 
            <Color x:Key="GridViewGroupPanelBackgroundGradientColor1">#FF616A76</Color> 
            <Color x:Key="GridViewGroupPanelBackgroundGradientColor2">#FF343639</Color> 
            <Color x:Key="GridViewGroupPanelBackgroundGradientColor3">#FF4D4D4D</Color> 
            <Color x:Key="GridViewGroupPanelBackgroundGradientColor4">#FF3A3B3D</Color> 
            <Color x:Key="GridViewGroupPanelBackgroundGradientColor5">#FF121212</Color> 
            <LinearGradientBrush x:Key="GridViewGroupPanelBackground" EndPoint="0.5,1" StartPoint="0.5,0">  
                <GradientStop Color="{StaticResource GridViewGroupPanelBackgroundGradientColor1}" Offset="0"/>  
                <GradientStop Color="{StaticResource GridViewGroupPanelBackgroundGradientColor2}" Offset="1"/>  
                <GradientStop Color="{StaticResource GridViewGroupPanelBackgroundGradientColor3}" Offset="0.02"/>  
                <GradientStop Color="{StaticResource GridViewGroupPanelBackgroundGradientColor4}" Offset="0.4"/>  
                <GradientStop Color="{StaticResource GridViewGroupPanelBackgroundGradientColor5}" Offset="0.41"/>  
            </LinearGradientBrush> 
            <Color x:Key="GridViewGroupingPanelElementsColor">#FFC9C6C6</Color> 
            <SolidColorBrush x:Key="GridViewGroupPanelForeground" Color="{StaticResource GridViewGroupingPanelElementsColor}"/>  
            <Color x:Key="GridViewBackgroundColor">#FF535353</Color> 
            <SolidColorBrush x:Key="GridViewGroupPanelBorderBrush" Color="{StaticResource GridViewBackgroundColor}"/>  
            <Style x:Key="GridViewItemsControlStyle" TargetType="gridView:GridViewItemsControl">  
                <Setter Property="Template" Value="{StaticResource GridViewItemsControlTemplate}"/>  
 
                <!--GroupPanel Customization Propoerties (ROOT GroupPanel)--> 
                <Setter Property="GroupPanelBackground" Value="#FFF3F6F9"/>  
                <Setter Property="GroupPanelForeground" Value="#FF000000"/>  
                <Setter Property="MinHeight" Value="26"/>  
                <Setter Property="BorderBrush" Value="{StaticResource GridViewGroupPanelBorderBrush}"/>  
                <Setter Property="BorderThickness" Value="0,0,0,1"/>  
            </Style> 
 
 
            <ControlTemplate x:Key="RadGridViewTemplate" TargetType="telerik:RadGridView">  
                <Border x:Name="PART_MasterGridContainer">  
                    <vsm:VisualStateManager.VisualStateGroups> 
                        <vsm:VisualStateGroup x:Name="GridViewActivity">  
                            <vsm:VisualState x:Name="Idle">  
                                <Storyboard> 
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_GridViewLoadingIndicator" Storyboard.TargetProperty="Visibility">  
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed"/>  
                                    </ObjectAnimationUsingKeyFrames> 
                                </Storyboard> 
                            </vsm:VisualState> 
                            <vsm:VisualState x:Name="Busy">  
                                <Storyboard> 
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_GridViewLoadingIndicator" Storyboard.TargetProperty="Visibility">  
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>  
                                    </ObjectAnimationUsingKeyFrames> 
                                </Storyboard> 
                            </vsm:VisualState> 
                        </vsm:VisualStateGroup> 
                    </vsm:VisualStateManager.VisualStateGroups> 
                    <Grid> 
                        <gridView:GridViewItemsControl x:Name="PART_RootItemsControl" Background="{TemplateBinding Background}" ParentRow="{TemplateBinding ParentRow}" ScrollMode="{TemplateBinding ScrollMode}" ShowColumnHeaders="{TemplateBinding ShowColumnHeaders}" ShowGroupPanel="{TemplateBinding ShowGroupPanel}" theme:StyleManager.Theme="{StaticResource Theme}" Style="{StaticResource GridViewItemsControlStyle}"/>  
                        <gridView:GridViewLoadingIndicator x:Name="PART_GridViewLoadingIndicator" Visibility="Collapsed" theme:StyleManager.Theme="{StaticResource Theme}"/>  
                    </Grid> 
                </Border> 
            </ControlTemplate> 
            <Color x:Key="GridViewElementOuterBorderBrushColor">#FFB3B3B3</Color> 
            <SolidColorBrush x:Key="GridViewCellBorderBrush" Color="{StaticResource GridViewElementOuterBorderBrushColor}"/>  
            <Color x:Key="GridViewBackgroundItemColor">#FF7F7F7F</Color> 
            <SolidColorBrush x:Key="GridViewBackgroundItemBackground" Color="{StaticResource GridViewBackgroundItemColor}"/>  
            <Style x:Key="RadGridViewStyle" TargetType="telerik:RadGridView">  
                <Setter Property="Template" Value="{StaticResource RadGridViewTemplate}"/>  
                <Setter Property="VerticalGridlinesBrush" Value="{StaticResource GridViewCellBorderBrush}"/>  
                <Setter Property="Background" Value="{StaticResource GridViewBackgroundItemBackground}"/>  
            </Style> 
 
 
 
            <!-- Cell Font 크기 --> 
            <Style x:Key="cellStyle" TargetType="gridView:GridViewCell">  
                <Setter Property="FontSize" Value="12" /> 
            </Style> 
 
        </Grid.Resources> 
 
        <Grid.RowDefinitions> 
            <RowDefinition Height="Auto" /> 
            <RowDefinition /> 
        </Grid.RowDefinitions> 
 
        <telerik:RadGridView Background="White" ColumnsWidthMode="None" Height="600" x:Name="RadGridView1"  AutoGenerateColumns="False" FontSize="12" Style="{StaticResource RadGridViewStyle}" > 
            <telerik:RadGridView.Columns> 
 
                <telerik:GridViewDataColumn CellStyle="{StaticResource cellStyle}"    
                    Width="120" IsFilterable="False" HeaderTextAlignment="Center" IsReadOnly="False" UniqueName="Phasenm" HeaderText="단계"/>  
 
                <telerik:GridViewDataColumn   
                    Width="120" IsFilterable="False" HeaderTextAlignment="Center" IsReadOnly="False" UniqueName="Tasknm" HeaderText="Task"/>  
 
                <telerik:GridViewDataColumn CellStyle="{StaticResource cellStyle}"   
                    Width="120" IsFilterable="False" HeaderTextAlignment="Center" UniqueName="Productnm" HeaderText="산출물"/>  
 
 
            </telerik:RadGridView.Columns> 
        </telerik:RadGridView> 
 
    </Grid> 
 
</UserControl> 
 


using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Net;  
using System.Windows;  
using System.Windows.Controls;  
using System.Windows.Documents;  
using System.Windows.Input;  
using System.Windows.Media;  
using System.Windows.Media.Animation;  
using System.Windows.Shapes;  
 
// Telerik using  
using Telerik.Windows;  
using Telerik.Windows.Data;  
using Telerik.Windows.Controls;  
using Telerik.Windows.Controls.GridView;  
using Telerik.Windows.Controls.GridView.Cells;  
 
// add using  
using System.Collections.ObjectModel;  
using System.Windows.Browser;  
using System.ComponentModel;  
using System.Collections;  
using System.Windows.Controls.Primitives;  
 
namespace SilverRadDynamicColumn  
{  
    public partial class Page : UserControl  
    {  
        public Page()  
        {  
            InitializeComponent();  
            //this.RadGridView1.DataLoaded += new EventHandler<EventArgs>(RadGridView1_DataLoaded);  
 
            //test data  
            MakeTestData();  
 
            LayoutDesign();  
 
        }  
 
        //void RadGridView1_DataLoaded(object sender, EventArgs e)  
        //{  
        //    foreach (var col in RadGridView1.Columns)  
        //    {  
        //        col.CellStyle = (Style)this.Resources["cellStyle"];  
        //    }  
        //}  
 
        public static List<TestData> list;  
 
        private void MakeTestData()  
        {  
            list = new List<TestData>();  
 
            for (int i = 0; i < 20; i++)  
            {  
                TestData td = new TestData();  
                td.Col1 = "Test";  
 
                list.Add(td);  
            }  
 
        }  
 
        private void LayoutDesign()  
        {  
            //Add Column  
            CreateColumn();  
 
            RadGridView1.ItemsSource = list;  
        }  
 
        private void CreateColumn()  
        {  
            GridViewColumn gc;  
 
            gc = new GridViewColumn();  
            gc.CellStyle = (Style)this.Resources["cellStyle"];  
            gc.Width = new GridLength(150);  
            gc.HeaderText = "단계";  
            gc.UniqueName = "Col1";  
 
            RadGridView1.Columns.Add(gc);  
 
            gc = new GridViewColumn();  
            gc.CellStyle = (Style)this.Resources["cellStyle"];  
            gc.Width = new GridLength(150);  
            gc.HeaderText = "Task";  
            gc.UniqueName = "Col1";  
            RadGridView1.Columns.Add(gc);  
 
            gc = new GridViewColumn();  
            gc.CellStyle = (Style)this.Resources["cellStyle"];  
            gc.Width = new GridLength(150);  
            gc.HeaderText = "산출물";  
            RadGridView1.Columns.Add(gc);  
 
            gc = new GridViewColumn();  
            gc.HeaderText = "추정치/\r\n표준작업시간";  
            RadGridView1.Columns.Add(gc);  
 
            gc = new GridViewColumn();  
            gc.HeaderText = "추정치/\r\n본당작업시간";  
            RadGridView1.Columns.Add(gc);  
 
 
        }  
    }  
 
    public class TestData  
    {  
        string _col1;  
 
        public string Col1  
        {  
            get { return _col1; }  
            set { _col1 = value; }  
        }  
    }  
}  
 

4 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 18 Aug 2009, 03:39 PM
Hello park,

You could try to create GridViewDataColumn objects in your CreateColumn method instead of GridViewColumn ones. That should fix the problem.

Regards,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
park
Top achievements
Rank 1
answered on 24 Aug 2009, 08:57 AM
An answer, thank you very much, 
The Edit mode is no problem, but when using GridViewDataColumn,
Cell Style can't be applied well.
I think it's understood when seeing a source,
Cell Style processing is needed,
so how can the part be done, please tell me.

        private void CreateColumn()  
        {  
            GridViewDataColumn gc;   
            //GridViewColumn gc;  
 
            gc = new GridViewDataColumn();  
            gc.CellStyle = (Style)this.Resources["cellStyle"];  
            gc.Width = new GridLength(150);  
            gc.HeaderText = "단계";  
            gc.UniqueName = "Col1"

            RadGridView1.Columns.Add(gc);
            ...
        }
0
Milan
Telerik team
answered on 25 Aug 2009, 02:49 PM
Hello park,

You have said that the CellStyle property cannod be applied well. Could you clarify a bit? Isn't the style applied to the cell?

Judging by your XAML you will probably need to move your custom cell style to the resource section of the UserControl since you will not be able to access the style easily from its current location.

Here is an example:

<UserControl x:Class="SilverRadDynamicColumn.Page"    
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"    
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"      
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"      
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"    
    xmlns:gridView="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView"    
    xmlns:theme="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"    
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"    
    Width="Auto" Height="600">     
<UserControl.Resources> 
    <Style x:Key="cellStyle" TargetType="gridView:GridViewCell">     
                <Setter Property="FontSize" Value="12" />    
     </Style>    
</UserControl.Resources> 
<Grid x:Name="LayoutRoot">  
<!--the rest of the code --> 


Greetings,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
park
Top achievements
Rank 1
answered on 30 Aug 2009, 02:38 AM
Fixed an issue. Thank you.
Tags
GridView
Asked by
park
Top achievements
Rank 1
Answers by
Milan
Telerik team
park
Top achievements
Rank 1
Share this question
or