Created
July 29, 2012 08:59
-
-
Save aturgarg/3196849 to your computer and use it in GitHub Desktop.
Datagrid dynamic checkbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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