http://www.cnblogs.com/kaixun001/archive/2009/02/16/1391722.html

DataGrid控件没有rows等属性我们如何全选与取消呢,在运用过程中做了个人小结,如果还有好方法,多多学习:

 hl3292修改

 //选择页面所有记录

 

 <sdk:DataGrid x:Name="BankPenaltyLogDataGrid" AutoGenerateColumns="False" Width="960" ColumnWidth="Auto" IsReadOnly="True" MouseLeftButtonUp="BankPenaltyLogDataGrid_MouseLeftButtonUp_1" SelectionChanged="BankPenaltyLogDataGrid_SelectionChanged_1">
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTemplateColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="状态"  Width="50">                   
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox x:Name="checkboxisCheck"></CheckBox>
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>
                    <!--<sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="序号"       Width="*"  MinWidth="50" Binding ="{Binding ID}"   />-->                   
                    <sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="日志类型"   Width="*"  MinWidth="50" MaxWidth="100" Binding ="{Binding log_type}"   />
                    <sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="调用时间"   Width="*"  MinWidth="50" MaxWidth="200" Binding ="{Binding use_time}"  />
                    <!--:格式转换-->
                <sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="决定书编号" Width="*"  MinWidth="50"  MaxWidth="150" Binding ="{Binding decision_no}"  />
                    <sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="输入信息"   Width="*"  MinWidth="50" MaxWidth="500" Binding ="{Binding input_info}"  />
                    <sdk:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="返回信息"   Width="*"  MinWidth="50" MaxWidth="500" Binding ="{Binding return_info}"  />
                    <sdk:DataGridTemplateColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="详细"   Width="*"  MinWidth="40" MaxWidth="60"   >
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <HyperlinkButton Content="详细" Click="HyperlinkButton_Click"/>
                                </StackPanel>
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>
                </sdk:DataGrid.Columns>

            </sdk:DataGrid>


       

//选择页面所有记录
        private void btnSeletcAll_Click(object sender, RoutedEventArgs e)
        {

            foreach (object ovj in BankPenaltyLogDataGrid.ItemsSource)
              
            {
                if (null != BankPenaltyLogDataGrid.Columns[0] && null != BankPenaltyLogDataGrid.Columns[0].GetCellContent(ovj)) 
                {
                    CheckBox cb = BankPenaltyLogDataGrid.Columns[0].GetCellContent(ovj).FindName("checkboxisCheck") as CheckBox;
                    if (null != cb)
                    {
                        cb.IsChecked = true;
                    }
                }              
            }

        }

        //反选
        private void btnSelectOther_Click(object sender, RoutedEventArgs e)
        {
            foreach (object ovj in BankPenaltyLogDataGrid.ItemsSource)
            {
                if (null != BankPenaltyLogDataGrid.Columns[0] && null != BankPenaltyLogDataGrid.Columns[0].GetCellContent(ovj))
                {
                    CheckBox cb = BankPenaltyLogDataGrid.Columns[0].GetCellContent(ovj).FindName("checkboxisCheck") as CheckBox;
                    if (null != cb)
                    {
                        cb.IsChecked = !cb.IsChecked;
                    }
                }

            }

        }

 

 

posted on 2010-11-19 14:37  hl3292  阅读(2034)  评论(5编辑  收藏  举报