DataGridCheckBoxColumn question, please help

Feb 2, 2009 at 9:12 PM
Hi, I have been trying to figure this out for whole day and it really drives me nuts....since I am very very new for WPF, I really need some help, please....
Here is my question.

I have a datagrid and the check box column will dynamicly add on when datagrid is loading. User can select only one row at one time. 

<

 

my:DataGrid Name="gvTest" xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit" ItemsSource="{Binding Tables[0]}" SelectedCellsChanged="gvTest_SelectedCellsChanged" >
<my:DataGrid.Columns>
<my:DataGridCheckBoxColumn Header="Checked" x:Name="chkSelected">
</my:DataGridCheckBoxColumn>
</my:DataGrid.Columns>
</my:DataGrid> 

 

 

 

private void gvTest_SelectedCellsChanged(object sender, Microsoft.Windows.Controls.SelectedCellsChangedEventArgs e)

{

foreach (DataGridRow row in gvTest.Items) --Unable to cast object of type 'System.Data.DataRowView' to type 'Microsoft.Windows.Controls.DataGridRow'.
{ 

 

DataGridCheckBoxColumn chk = row.FindName("chkSelected") as DataGridCheckBoxColumn  
if(chk.Checked) -- I want to see if the check box is checked.
{
btn.DataContext = "Hello";
}

}
}

 

 

 

Coordinator
Feb 4, 2009 at 12:12 PM
Take a look at the GetRow and GetCell methods here, http://www.codeplex.com/wpf/Thread/View.aspx?ThreadId=34065.