简体   繁体   English

如何在Silverlight中使用DataGrid中的复选框

[英]How to use checkbox in datagrid in silverlight

i am making an application in silver light.In that application i am using data grid as 我正在使用Silver Light。在那个应用程序中,我正在使用数据网格作为

 <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. 1.在数据网格上设置一个选择更改事件,每当选择一行时,都会修改该方面的绑定复选框。

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: 如果您需要更多控件,例如在选中复选框时触发事件,我将使用DataTemplate重新放置DataGridColum,例如:

<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");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM