zoukankan      html  css  js  c++  java
  • WPF DataGrid显示按上下键移动数据、多个CheckBox勾选

    1、DataGrid显示数据选中后按上下键移动数据

    //xaml 在DataGrid中加入事件
    PreviewKeyDown = "keyDownSetSeq"
    //cs文件中加code 用System.Collections.ObjectModel的Move方法
    private void keyDownSetSeq(object sender, KeyEventArgs e)
    {
        int count = dataGrid.Items.Count;
        int index = dataGrid.SelectedIndex;
        if(index < 0) return;
        if(e.Key == Key.Up){
            if(index-1 < 0){
                e.Handled = true;//设为true,表示事件已经处理了,那么keypress事件将会取消
                return;
            }
            SelectLotListTemp.Move(index, index-1);//SelectLotListTemp得到的数据源
            dataGrid.DataContext = null;
            dataGrid.DataContext = SelectLotListTemp;
            dataGrid.SelectedIndex = index - 1;
        }
        if(e.Key == Key.Down){
            if(index +1 >= count){
                e.Handled = true;
                return;
            }
            SelectLotListTemp.Move(index, index+1);//SelectLotListTemp得到的数据源
            dataGrid.DataContext = null;
            dataGrid.DataContext = SelectLotListTemp;
            dataGrid.SelectedIndex = index + 1;
        }
    }
        
        
    
    
    

    2、DataGrid显示数据排序 使用System.Collection.Generic里面的Sort方法排序

    3、界面多个CheckBox勾选

    CheckBox checkBox = sender as CheckBox;
    foreach(var c in grid.Children){
        if(c is CheckBox){
            CheckBox temp = (CheckBox)c;
            temp.IsChecked = true;
        }
    }
    
  • 相关阅读:
    有继承的C++析构函数一定要用virtual
    CUDA vs2010配置
    lambda calculus(1)
    SICP练习1.6 1.16 解答
    用函数式来实现集合
    osx guile编译安装
    skiplist poj2892
    [转]理解 pkgconfig 工具
    专业术语解释
    【转】如何学习linux设备驱动
  • 原文地址:https://www.cnblogs.com/DingGuo/p/14297442.html
Copyright © 2011-2022 走看看