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

RadGridView AutoGenerateColumns as True and GridViewColumns Template

11 Answers 1115 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pradnya
Top achievements
Rank 1
Pradnya asked on 11 May 2012, 11:24 AM
Hi,

I am using RadGridView in Silverlight application and binding it to a DataTable . For my RadGridView I have set AutoGenerateColumns = "True" (to get my columns automatically). 

Now I want add two GridViewColumns Template having some Imgae control inside it.

So how can I implement this Scenario with setting AutoGenerateColumns = "True"

Thanks-

 

11 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 11 May 2012, 11:51 AM
Hello Pradnya,

There are two options for you :

1. You can manually define the two special columns. RadGridView will display them along with the autogenerated columns.

2. You can handle the AutogeneratingColumn event , and assign your templates inside the event handler for the columns RadGridView has generated for you.

Regards,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Pradnya
Top achievements
Rank 1
answered on 11 May 2012, 11:56 AM
Thanks a lots for your valuable reply

How can I manually define the two special columns. Can you provide some sample code for same

Thanks-
0
Pavel Pavlov
Telerik team
answered on 11 May 2012, 12:30 PM
Hi,

Some XAML for manually defining an image column may be found here.

All the best,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Pradnya
Top achievements
Rank 1
answered on 11 May 2012, 12:40 PM
Hi Pavel

I have set AutoGenerateColumns = "True" in that case it removed static columns and only display column from DataTable

So how can I add my static column with Auto Generated column.

Thanks-
0
Pavel Pavlov
Telerik team
answered on 11 May 2012, 01:06 PM
Hi,

That is confusing. By design RadGridView will show manually defined columns along with the autogenerated.
We have never observed the behavior described.
I sounds like you have hit a bug . Can you please share your XAML/cs  with me so I can test it here.

Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Pradnya
Top achievements
Rank 1
answered on 11 May 2012, 01:26 PM
This is XAM:

<telerik:RadGridView x:Name="tableDataGrid" Grid.Row="0" IsReadOnly="True" CanUserSortColumns="False" CanUserResizeColumns="False" CanUserReorderColumns="False"
                                 CanUserFreezeColumns="False" CanUserDeleteRows="False" CanUserInsertRows="False" CanUserSelect="True" RowIndicatorVisibility="Collapsed"
                                 ShowGroupPanel="False" HorizontalAlignment="Stretch" DataContext="{Binding TableData}" SelectionChanged="tableGrid_SelectionChanged"
                                 AutoGeneratingColumn="tableDataGrid_AutoGeneratingColumn">
                    <telerik:RadGridView.Columns>
                       
                        <telerik:GridViewColumn Header="Text" Background="WhiteSmoke" IsSortable="False" IsFilterable="False" Width="45" IsReadOnly="True">
                            <telerik:GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                        <HyperlinkButton BorderThickness="0" Foreground="#FF034CFF" Margin="4,0,2,0" x:Name="addRowButton" HorizontalAlignment="Right" Click="addRowtButton_Click"
                                         Background="Transparent" VerticalAlignment="Top" ToolTipService.ToolTip="Insert new row">
                                            <Image Source="/Toolbox;component/Images/AddRow.png" Height="20"></Image>
                                        </HyperlinkButton>
                                    </StackPanel>
                                </DataTemplate>
                            </telerik:GridViewColumn.CellTemplate>
                        </telerik:GridViewColumn>
                    </telerik:RadGridView.Columns>
                </telerik:RadGridView>

It removed my static column that is Hyperlinklink button image.
0
Pavel Pavlov
Telerik team
answered on 11 May 2012, 01:58 PM
Hi Pradnya,

I gathered your XAML in a project . It displays both the autogenerated and the manually set column .
You can find it attached.

All the best,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Pradnya
Top achievements
Rank 1
answered on 14 May 2012, 06:20 AM
Thank you for solution it works for me.

I have two static columns like [ one is for "Add New Row" and other is "Delete Row"] and In between I want add Auto Genrated columns

How Can I implement this scenario?

<telerik:RadGridView x:Name="tableDataGrid" Grid.Row="0" IsReadOnly="True" CanUserSortColumns="False" CanUserResizeColumns="False" CanUserReorderColumns="False"
                                 CanUserFreezeColumns="False" CanUserDeleteRows="False" CanUserInsertRows="False" CanUserSelect="True" RowIndicatorVisibility="Collapsed"
                                  ShowGroupPanel="False" HorizontalAlignment="Stretch"  ItemsSource="{Binding TableData}"
                                  >
   <telerik:RadGridView.Columns>

    <telerik:GridViewColumn Header="Text" Background="WhiteSmoke" IsSortable="False" IsFilterable="False" Width="45" IsReadOnly="True">
     <telerik:GridViewColumn.CellTemplate>
      <DataTemplate>
       <StackPanel>
        <HyperlinkButton BorderThickness="0" Foreground="#FF034CFF" Margin="4,0,2,0" x:Name="addRowButton" HorizontalAlignment="Right"
                                         Background="Transparent" VerticalAlignment="Top" ToolTipService.ToolTip="Insert new row">
         <Image Source="/Toolbox;component/Images/AddRow.png" Height="20"></Image>
        </HyperlinkButton>
       </StackPanel>
      </DataTemplate>
     </telerik:GridViewColumn.CellTemplate>
    </telerik:GridViewColumn>

                <telerik:GridViewColumn  IsSortable="False" IsFilterable="False" Width="30" Background="White" IsReadOnly="True">
                    <telerik:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <HyperlinkButton BorderThickness="0" Foreground="#FF034CFF" x:Name="deleteRuleInfoRowButton" HorizontalAlignment="Right" Click="deleteRuleInfoRowButton_Click"
                                         Background="Transparent" VerticalAlignment="Top" ToolTipService.ToolTip="Delete">
                                    <Image Source="/Toolbox;component/Images/Delete.png" Height="16"></Image>
                                </HyperlinkButton>
                            </StackPanel>
                        </DataTemplate>
                    </telerik:GridViewColumn.CellTemplate>
                </telerik:GridViewColumn>
            </telerik:RadGridView.Columns>
  </telerik:RadGridView>

Thanks-

0
Accepted
Pavel Pavlov
Telerik team
answered on 16 May 2012, 09:21 AM
Hi Pradnya,

You can control the order of appearance of the columns using their DisplayIndex property.

Regards,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Fredy
Top achievements
Rank 1
answered on 21 Jul 2012, 06:04 AM
1) How can I generate a columns to a combobox (RadViewComboboxColumn)?. My radgridview Itemsource is binding to my TestDataViewModel class, some propertys are enum types (after will be dynamic data...) and AutoGenerateColumn must be True.

Show the data!, but don't convert the column to a combobox with the data (enum) options!.

2) And how can I put numerical values ​​on the right side of the column? with
AutoGenerateColumns="True" too.
Help me pls!
(SL5 and Telerik 2012.2.607.1050)
My Code here: http://sdrv.ms/SMC5j4

0
Andreas
Top achievements
Rank 1
answered on 24 Jan 2013, 01:09 PM
Hey Fredy,

dont know if you still need this solved. For you second point i can give you this:
HowTo: Enabling custom attributes to GridView

Simply use the things described there and use a new custom attribute which uses something like this
public override void UpdateColumn(GridViewColumn column)
{
    column.ShowDistinctFilters = DistinctFilters;
    column.TextAlignment = TextAlignment.Right;
}

For the first one, i am currently looking into a possibility to change the type of the autogenerated column to a specific one.
Such as the auto generated GridViewDataColumn to GridViewComboBoxColumn and others.
Since some enum types are not converting for me either (especially in their editing modes).
Tags
GridView
Asked by
Pradnya
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Pradnya
Top achievements
Rank 1
Fredy
Top achievements
Rank 1
Andreas
Top achievements
Rank 1
Share this question
or