Skip to content

Instantly share code, notes, and snippets.

@aturgarg
Created July 29, 2012 08:59
Show Gist options
  • Save aturgarg/3196849 to your computer and use it in GitHub Desktop.
Save aturgarg/3196849 to your computer and use it in GitHub Desktop.
Datagrid dynamic checkbox
There is no click event in datagrid's checkcolumn, but the checkbox control has a click event, so you can try to use the datagrid's template column and place a checkbox in template, and add code to checkbox click event code block.
You can try to pre-define the checkbox in the a datatemplate in the usercontro.resource tags, and register the checkbox event, like below:
<UserControl.Resources>
<DataTemplate x:Key="myCellTemplate">
<CheckBox Click="CheckBox_Click"></CheckBox>
</DataTemplate>
</UserControl.Resources>
Then, you can add the datatempate to the datagrid's templatecolumn programmatically:
DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();
templateColumn.Header = "hello";
templateColumn.CellTemplate = (DataTemplate)Resources["myCellTemplate"];
targetDataGrid.Columns.Add(templateColumn);
also see :-
http://blogs.msdn.com/scmorris/archive/2008/04/14/defining-silverlight-datagrid-columns-at-runtime.aspx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment