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

Click Handler Add to Checkbox in GridViewDataColumn

5 Answers 262 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Johann
Top achievements
Rank 1
Johann asked on 05 Mar 2012, 08:29 AM
Hi,

i add a ClickHandler to a CheckBox in a GridViewDataColumn in Codebehind. But this dont fired the Handler when i click the CheckBox.
Can you please show me the right way to do this?

Thank You
.

Here a Code Snippet

col = new GridViewDataColumn
                            {
                                Header = vspriorities[key],
                                CellTemplate = new DataTemplate()
                            };
  
  
                            cbx = new FrameworkElementFactory(typeof(CheckBox)); ;
                                cbx.SetValue(IsHitTestVisibleProperty, true);
                                cbx.SetValue(FocusableProperty, true);
                                cbx.SetValue(TagProperty, null);
                                cbx.SetValue(MarginProperty, new Thickness(0, 0, 0, 0));
                                cbx.SetValue(TagProperty, key);
                                cbx.SetBinding(DataContextProperty, new Binding());
                                cbx.SetBinding(CheckBox.IsCheckedProperty, new Binding("PrioritaetId") { ConverterParameter = key, Converter = (IValueConverter)TryFindResource("EqualsConverter"), Mode = BindingMode.OneTime });
  
                                //cbx.AddHandler(GridViewCheckBox.ClickEvent, new RoutedEventHandler(VSPriority_Checked));
  
                                cbx.AddHandler(CheckBox.ClickEvent, new RoutedEventHandler (VSPriority_Checked));
  
                             
  
                                //templBorder = new FrameworkElementFactory(typeof(Border));
                                //templBorder.SetValue(StyleProperty, TryFindResource("GridBorder"));
                                  
                                //templBorder.AppendChild(cbx);
  
  
  
                            col.CellTemplate.VisualTree = cbx;
                            col.CellTemplate.Seal();
                           
  
                            StatusColumns.Add(col);
  
                            lvData.Columns.Insert(idx++, col);

5 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 05 Mar 2012, 08:47 AM
Hi,

 Maybe it will be better to inherit from GridViewDataColumn, override CrateCellElement and create desired component with desired events. You can check this demo for more info. The example is for Silverlight however you can find exactly the same in your local copy of our WPF demos. 

All the best,
Vlad
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Johann
Top achievements
Rank 1
answered on 05 Mar 2012, 10:31 AM
Hi,

thank you for your fast reply

But how can i create a custom column only over code behind. in my Application there should be a variable count of this Columns.
I want to create the Columns only over Codebehind at the Runtime.

Sorry for my bad English. I hope you understand what i mean.

greetings Johann

0
Vlad
Telerik team
answered on 05 Mar 2012, 10:37 AM
Hi Johann,

 You can create column in code and add them to the columns collection. For example:

var column = new MyCustomColumn();
...
RadGridView1.Columns.Add(column);

All the best,
Vlad
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Johann
Top achievements
Rank 1
answered on 05 Mar 2012, 12:15 PM
Hi

thank you for your reply.

i habe tested it, but i dont bring it to work. The ColumnAdd is no Problem, but the added ClickHandler wont work.

can you please provide me with a simple demo?

I want add the columns with Checkbox only at runtime from Codebehind with added ClickHandler for the Checkboxes

Thank you for your help.

Johann
0
Pasquale Zirpoli
Top achievements
Rank 1
answered on 24 Jul 2012, 09:46 AM
Seems that AddHandler for a FrameworkElementFactory won't work, event are never called ...

here follows the test code

foreach (var c in radGridViewTest.Columns)

            {


                        var factory = new FrameworkElementFactory(typeof(Button), "myButton");

                        factory.SetValue(CursorProperty, Cursors.Hand); // OK

                        factory.SetBinding(ContentProperty, new Binding(string.Format("[{0}]", 4))); //OK

                        c.CellTemplate= new DataTemplate();

                        

                        var mh = new RoutedEventHandler(onClick);

                        factory.AddHandler(Button.ClickEvent, mh,true); // won't work ...

                        c.CellTemplate.VisualTree = factory;

                        c.CellTemplate.Seal();
            }


Tags
GridView
Asked by
Johann
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Johann
Top achievements
Rank 1
Pasquale Zirpoli
Top achievements
Rank 1
Share this question
or