RadGridView AutoGenerateColumns as True and GridViewColumns Template

12 posts, 1 answers
  1. Pradnya
    Pradnya avatar
    31 posts
    Member since:
    Aug 2011

    Posted 11 May 2012 Link to this post

    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-

     
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 11 May 2012 Link to this post

    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 >>

  3. DevCraft banner
  4. Pradnya
    Pradnya avatar
    31 posts
    Member since:
    Aug 2011

    Posted 11 May 2012 Link to this post

    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-
  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 11 May 2012 Link to this post

    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 >>

  6. Pradnya
    Pradnya avatar
    31 posts
    Member since:
    Aug 2011

    Posted 11 May 2012 Link to this post

    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-
  7. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 11 May 2012 Link to this post

    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 >>

  8. Pradnya
    Pradnya avatar
    31 posts
    Member since:
    Aug 2011

    Posted 11 May 2012 Link to this post

    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.
  9. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 11 May 2012 Link to this post

    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 >>

  10. Pradnya
    Pradnya avatar
    31 posts
    Member since:
    Aug 2011

    Posted 14 May 2012 Link to this post

    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-

  11. Answer
    Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 16 May 2012 Link to this post

    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 >>

  12. Fredy
    Fredy avatar
    7 posts
    Member since:
    Mar 2012

    Posted 21 Jul 2012 Link to this post

    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

  13. Andreas
    Andreas avatar
    8 posts
    Member since:
    Nov 2012

    Posted 24 Jan 2013 Link to this post

    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).
Back to Top
DevCraft banner