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

Cannot add Column Dynamically

2 Answers 111 Views
GridView
This is a migrated thread and some comments may be shown as answers.
om
Top achievements
Rank 1
om asked on 25 Aug 2009, 06:27 PM
I just started using Telerik Grid instead of MS based Grid.
I just tried to Add and clear columns dynamically into the grid but I couldn't find the appropirate functions in intellisense.
I tried "this.radResult.Columns.Add(dyncol)" but, I Couldn't find "Add" in intellisense, couldn't find "Clear" method in intellisense as either.

<UserControl    x:Class="SolutionQ.Eclipse.Silverlight.Content.Search.xxxx.xxxx.xxxxxxxx" 
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
                xmlns:dg="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" 
                xmlns:RadNav="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" 
                xmlns:controls="clr-namespace:SolutionQ.Eclipse.Silverlight.Content.Controls"            
                xmlns:RadGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 
                xmlns:GridView="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView"   
> 
    <Grid x:Name="LayoutRoot" Background="White">  
        <Grid.RowDefinitions> 
            <!--xmlns:Ra=""--> 
            <RowDefinition Height="Auto" /> 
            <RowDefinition Height="1*" /> 
        </Grid.RowDefinitions> 
 
        <Grid.ColumnDefinitions> 
            <ColumnDefinition Width="1*" /> 
        </Grid.ColumnDefinitions> 
 
        <!-- Filtering ToolBar --> 
        <RadNav:RadToolBarTray Grid.Row="0" Grid.Column="0" Style="{StaticResource style_DataGridRadToolBarTray}">  
            <RadNav:RadToolBar x:Name="rtb_Filter" Style="{StaticResource style_RadToolBar}">  
                <!-- New Clause Button --> 
                <Button x:Name="btn_ExportToExcel" Tag="btn_ExportToExcel" Click="btn_Menu_Click" ToolTipService.ToolTip="Export to Excel Format">  
                    <controls:IconAndLabelControl Icon="Icons/PlaceHolderIcon.xaml" Label="Export To Excel" /> 
                </Button> 
                <Button x:Name="btn_ViewResults" Tag="btn_ViewResults" Click="btn_Menu_Click" ToolTipService.ToolTip="View Results">  
                    <controls:IconAndLabelControl Icon="Icons/PlaceHolderIcon.xaml" Label="View Results" /> 
                </Button> 
            </RadNav:RadToolBar> 
        </RadNav:RadToolBarTray> 
          
        <!--<dg:DataGrid x:Name="Result" Grid.Row="1" Grid.Column="0" AutoGenerateColumns="False" ItemsSource="{Binding Path=Items, Mode=TwoWay}" Style="{StaticResource style_GenericDataGrid}" CellStyle="{StaticResource style_GenericDataGridCell}" ColumnHeaderStyle="{StaticResource style_GenericDataGridColumnHeader_LeftAligned}" RowHeaderStyle="{StaticResource style_GenericDataGridRowHeader}" RowStyle="{StaticResource style_GenericDataGridRow}">  
        </dg:DataGrid>--> 
        <RadGrid:RadGridView x:Name="radResult" Grid.Row="1" Grid.Column="0" AutoGenerateColumns="False" > 
        <!--ItemsSource="{Binding Path=Items, Mode=TwoWay}"--> 
        </RadGrid:RadGridView> 
    </Grid> 
 
</UserControl> 
 

 

 

 

 

 

At code behind side I am using following namespaces:

 

 

 

 

 

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;   

 

 

 

 

void tabPreview_Loaded(object sender, RoutedEventArgs e)   
{  
    BuildColumns();   
}   
 
private void BuildColumns()   
{  
   this.radResult.Columns.Clear(); //<-- This method doesnt show in intellisense, neither Add method will show up here   
}  
 

Am I doing anything wrong here?

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Milan
Telerik team
answered on 28 Aug 2009, 02:26 PM
Hi om,

I have attached a sample application that demonstares how you can add or clear grid columns.
Hope this helps.

All the best,
Milan
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
om
Top achievements
Rank 1
answered on 28 Aug 2009, 02:34 PM
Oh, thanks for your reply, I was actually missing a reference of  "Telerik.Windows.Data"
Tags
GridView
Asked by
om
Top achievements
Rank 1
Answers by
Milan
Telerik team
om
Top achievements
Rank 1
Share this question
or