This question is locked. New answers and comments are not allowed.
Hello,
I was reading the following article, http://www.telerik.com/community/forums/silverlight/treelist/add-event-to-datatemplate-in-code-behind.aspx, and I was wondering if this was possible to do with the RadGridView. I want to add the Checked and Unchecked events to my checkbox columns. Here is my code: (Where dgContacts is my dataGrid and "cb"+ct is the name of my checkbox)
However, what happens is that the count of the "VisualTreeHelper.GetChildernCount(obj)" is 0 everytime.
Is there a way to add events to this checkbox???
Thanks,
I was reading the following article, http://www.telerik.com/community/forums/silverlight/treelist/add-event-to-datatemplate-in-code-behind.aspx, and I was wondering if this was possible to do with the RadGridView. I want to add the Checked and Unchecked events to my checkbox columns. Here is my code: (Where dgContacts is my dataGrid and "cb"+ct is the name of my checkbox)
| private void AddColumns() |
| { |
| for (var ct = 0; ct < 10; ct++) |
| { |
| var column = new GridViewDataColumn(); |
| column.Header = "This is a List" + ct; |
| var myXamlString = "<DataTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"><CheckBox x:Name=\"cb" + ct + "\" IsThreeState=\"False\" VerticalAlignment=\"Center\" IsChecked=\"{Binding List" + ct + ", Mode=TwoWay}\"/></DataTemplate>"; |
| var template = (DataTemplate) XamlReader.Load(myXamlString); |
| column.CellTemplate = template; |
| column.DataMemberBinding = new System.Windows.Data.Binding("List" + ct); |
| dgContacts.Columns.Add(column); |
| GetChildObject<CheckBox>(dgContacts, "cb" + ct); |
| } |
| } |
| public void GetChildObject<T>(DependencyObject obj, string name) where T : DependencyObject |
| { |
| for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) |
| { |
| DependencyObject c = VisualTreeHelper.GetChild(obj, i); |
| if (c.GetType().Equals(typeof(T)) && (string.IsNullOrEmpty(name) || ((FrameworkElement)c).Name == name)) |
| { |
| CheckBox chk = (CheckBox)c |
| chk.Checked += new RoutedEventHandler(CheckBox_Checked); |
| continue; |
| } |
| GetChildObject<T>(c, name); |
| } |
| } |
However, what happens is that the count of the "VisualTreeHelper.GetChildernCount(obj)" is 0 everytime.
Is there a way to add events to this checkbox???
Thanks,
