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

Trying to add a button to a column header

3 Answers 239 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.
Adam
Top achievements
Rank 1
Adam asked on 14 Dec 2010, 10:12 PM
Hi, I am trying to add a button to a column header however the click event does not seem to be handled.  Currently I am instructing it to insert a new row simply to test it's functionality.  I have insured that it is simply because the button is in the header that it does not function by using the same command for a button within a cell.  Please help me understand what needs to be done, my code for the specific column is below.

               <telerik:GridViewColumn>
                    <telerik:GridViewColumn.Header>
                        <telerik:RadButton Style="{StaticResource Remove/Add_From_List_Button_Style}" Content="+" FontFamily="Arial" FontSize="18" FontWeight="Bold" Foreground="Green" Command="telerik:RadGridViewCommands.BeginInsert" Margin="0"/>
                    </telerik:GridViewColumn.Header>
                    <telerik:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <telerik:RadButton Style="{StaticResource Remove/Add_From_List_Button_Style}" Content="X" FontFamily="Arial" FontSize="12" FontWeight="Bold" Foreground="Red" Command="telerik:RadGridViewCommands.Delete"/>
                        </DataTemplate>
                    </telerik:GridViewColumn.CellTemplate>
                </telerik:GridViewColumn> 

Thanks,
Adam Burdette

3 Answers, 1 is accepted

Sort by
0
Accepted
Vanya Pavlova
Telerik team
answered on 15 Dec 2010, 12:25 PM
Hi Adam,

 
Thank you for this code snippet.

The button in the header executes the BeginInsert Command of RadGridView, and the button in its CellTemplate executes the Delete command, which removes the selected item from the collection. Also I specified the CommandParameter Property's Binding to be the entire object. Please check the attached project and let me know how if you need any further assistance.

Feel free to modify it and send it back to me if needed.

Best wishes,
Vanya Pavlova
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Adam
Top achievements
Rank 1
answered on 15 Dec 2010, 02:49 PM
Vanya,
So your code works just the way I want it to, however upon further testing and trying to implement the differences I saw in my own project, it appears that this only works because you have sample data bound to the control.  If I do everything but define and bind sample data the functionality of the controls starts to act strangely. At first the button doesn't work at all, but eventually, seemingly after loosing focus, if I press it again it will start a new row and insert the row that it did not display earlier.  Then if I press the commit button on the left side of the new row it displays the Insert Row control when the ShowInsertRow property is defiantly false.

I don't understand why it is necessary to have sample data bound to the grid in order for it to display a new empty row defined by the columns collection in this instance and not for the InsertRow control. 

Eventually, this button will not add a new row but activate the pinned property of a docking control so this is not of great importance.  I just wanted a simple test of functionality on a button defined in the column header such that I knew it was possible.  I'm sure now that it is and figuring out how to get it to pin the docking panel will be my next hurtle. 

Thank you for your time,
Adam Burdette
0
Adam
Top achievements
Rank 1
answered on 15 Dec 2010, 03:27 PM
Actually I take back part of my statement above, I will need this for my project.  There is one grid that implements this behavior specifically.
Tags
GridView
Asked by
Adam
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Adam
Top achievements
Rank 1
Share this question
or