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;
        }
    }
    
  • 相关阅读:
    生产环境Crontab专业实例
    Linux系统定时任务介绍
    Linux文件属性改变命令chown-chgrp-chattr-lsattr实践
    Linux命令总结
    Linux特殊权限位suid、sgid深度详细及实践
    企业场景-网站目录安全权限深度讲解及umask知识
    shell简介
    Nginx模块及配置虚拟主机
    安装Nginx
    Nginx简介
  • 原文地址:https://www.cnblogs.com/DingGuo/p/14297442.html
Copyright © 2011-2022 走看看