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

Add button column in code dynamically with click event handler

2 Answers 438 Views
GridView
This is a migrated thread and some comments may be shown as answers.
JC
Top achievements
Rank 1
JC asked on 21 Oct 2011, 09:20 PM
Hello, I'm having trouble figuring out how to add a button dynamically in a radgridview.

I'm porting over working code that used the stock WPF DataGrid control.  This is the method I *used* to use:

  private DataGridTemplateColumn GetButtonColumn(IListPropertyInfo i)
       {
           var buttonTemplate = new FrameworkElementFactory(typeof(Button));          
           buttonTemplate.SetBinding(Button.ContentProperty, new Binding(i.columnName));
           buttonTemplate.SetValue(Button.StyleProperty, DefaultStyles.GridColumnButtonStyle); 

           buttonTemplate.AddHandler(
              Button.ClickEvent,
              new RoutedEventHandler((o, e) => HandleColumnButtonClick(o, e))
          );

           DataGridTemplateColumn c = new DataGridTemplateColumn();
           c.SortMemberPath = i.columnName;
           c.CellTemplate=new DataTemplate() { VisualTree = buttonTemplate };
           AddHeader(c,i);
           return c;
       }

Trying to replicate this using the RadGridView is giving me all sorts of problems, I think I'm going about it entirely wrong so I won't even post my failed attempts as I'm getting all sorts of bizarre errors.

How do I accomplish adding a button column dynamically in code to a RadGridView and setting it to my own event handler (there is an example on here but it's done in xaml and doesn't add an event handler for the button)?

Any help greatly appreciated.

2 Answers, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 24 Oct 2011, 06:57 AM
Hello Joyce,

You can try to create your own custom column with a RadButton defined for its CellTemplate element. Please take a look at our online documentation and blog posts for a reference.
Will that approach suit your needs? 

Regards,
Maya
the Telerik team

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

0
JC
Top achievements
Rank 1
answered on 24 Oct 2011, 06:14 PM
Thank you for your reply.


Tags
GridView
Asked by
JC
Top achievements
Rank 1
Answers by
Maya
Telerik team
JC
Top achievements
Rank 1
Share this question
or