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

[Solved] Adding Control to Custom Hierarchy Column

1 Answer 130 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.
John Morris
Top achievements
Rank 1
John Morris asked on 19 Jan 2010, 06:59 PM
I'm revising my grids to not use PreviewDataRecordCreate with the Q3 release and I'm following the Custom Hierarchy example.  Everything works great except I cannot determine how to dynamically add a button to a column in my DataLoading event.

This is the XAML of what I'm trying to reproduce in code.

 

 <telerikGridView:GridViewDataColumn Width="50" > 
                                       <telerikGridView:GridViewDataColumn.CellStyle> 
                                            <Style TargetType="Telerik_Windows_Controls_GridView:GridViewCell">  
                                                <Setter Property="Template">  
                                                    <Setter.Value> 
                                                        <ControlTemplate TargetType="Telerik_Windows_Controls_GridView:GridViewCell">  
                                                            <Button Click="ReportSelectCommand"   
                                                                HorizontalAlignment="Center"  Content="Resume" ToolTipService.ToolTip="Continue saved report"      
                                                                VerticalAlignment="Center" DataContext="{Binding id}">  
                                                            </Button> 
                                                        </ControlTemplate> 
                                                    </Setter.Value> 
                                                </Setter> 
                                            </Style> 
                                        </telerikGridView:GridViewDataColumn.CellStyle> 
                                    </telerikGridView:GridViewDataColumn> 


My DataLoading event - I cannot determine how to add the button control to the first datacolumn.

        private void grdReports_DataLoading(object sender, GridViewDataLoadingEventArgs e)  
        {  
            GridViewDataControl dataControl = (GridViewDataControl)sender;  
            if (dataControl.ParentRow != null)  
            {  
                dataControl.CanUserFreezeColumns = false;  
                dataControl.ShowGroupPanel = false;  
                dataControl.AutoGenerateColumns = false;  
                dataControl.ColumnsWidthMode = ColumnsWidthMode.Fill;  
 
                // THIS IS AS FAR AS I GOT.  NOT SURE HOW TO ADD A CONTROL TO A CELL  
                GridViewDataColumn column = new GridViewDataColumn();  
                column.CellStyle.TargetType = typeof(Telerik.Windows.Controls.GridView.GridViewCell);                  
 
                ///////////////////////////////////////////////////////////////////////  
 
                column = new GridViewDataColumn();  
                column.Header = "Title";  
                column.DataMemberBinding = new System.Windows.Data.Binding("assocname");  
                dataControl.Columns.Add(column);  
 
                column = new GridViewDataColumn();  
                column.Header = "Date Created";  
                column.DataMemberBinding = new System.Windows.Data.Binding("createDate");  
                dataControl.Columns.Add(column);  
 
                column = new GridViewDataColumn();  
                column.Header = "Current Page";  
                column.DataFormatString = "{0:c}";  
                column.DataMemberBinding = new System.Windows.Data.Binding("CurrentPage");  
                dataControl.Columns.Add(column);  
 
                column = new GridViewDataColumn();  
                column.Header = "Components";  
                column.DataMemberBinding = new System.Windows.Data.Binding("compCount");  
                dataControl.Columns.Add(column);  
            }  
        } 

 Thank you.

 

 

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 20 Jan 2010, 07:02 AM
Hi John Morris,

You can create your own column, override CreateCellElement and return desired control. Please check this post for more info:
http://blogs.telerik.com/nedyalkonikolov/posts/09-11-12/how_to_create_custom_editor_with_radgridview_for_silverlight_and_wpf.aspx

Sincerely yours,
Vlad
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.
Tags
GridView
Asked by
John Morris
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or