问题描述:

i am making an application in silver light.In that application i am using data grid as

 <data:DataGrid Grid.Row="1" HorizontalAlignment="Left" IsReadOnly="True" Name="dataGrid1" VerticalAlignment="Top" AutoGenerateColumns="False" DataContext="{Binding}" SelectionMode="Single" LoadingRow="ResultsGrid_LoadingRow">

<data:DataGrid.Columns>

<data:DataGridTextColumn Header=" BedId " Binding="{Binding BedID }" />

<data:DataGridTextColumn Header="PatientName" Binding="{Binding PatientName}" />

<data:DataGridTextColumn Header="AdmitDate" Binding="{Binding AdmitDate}" />

<data:DataGridTextColumn Header="BirthDate" Binding="{Binding BirthDate}" />

<data:DataGridCheckBoxColumn Header="checkbox" Binding="{ Binding }" IsReadOnly="False" />

</data:DataGrid.Columns>

</data:DataGrid>

Whenever in my application i am loading the data grid, it shows the data grid along with respective values.In my application i want to show the check box in front of every column and above code shows the check box in front of every column. but whenever i am clicking on that check box it doesn't shows any check event.i want to select single or multiple check boxes as per condition.But i am not getting how to do it.Please help me.Thanks in advance.

网友答案:

You have a few options. 1. Setup a selection changed event on the datagrid and whenever a row is selected modify the bound checkbox in that aspect.

If you need more control such as an event to fire when the checkbox is selected I would repalce the DataGridColum with an DataTemplate such as:

<DataGridTemplateColumn Header="Checkbox">
<DataGridTemplateColumn.CellTemplate>
      <DataTemplate>
           <CheckBox IsChecked="{Binding Path=someProperty, UpdateSourceTrigger=PropertyChanged}" Click="CheckBox_Click"/>
     </DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

Then in your code behind

private void CheckBox_Click(object sender, RoutedEventArgs e)
{
//I realize you don't have message box in silverlight but this demonstrates the firing of the event
MessageBox.Show("click");
}
相关阅读:
Top