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;
        }
    }
    
  • 相关阅读:
    关于ShareSDK接入的各种问题,以及解决方案
    Cocos2d-x使用iOS游戏内付费IAP(C++篇)
    数论——终结素数判定
    poj 2528 线段树+离散化
    STL 优先队列
    poj 2777 线段树+延迟更新
    RMQ
    codeforces 拼手速题2
    codeforces 拼手速题1
    子矩阵 思维吧
  • 原文地址:https://www.cnblogs.com/DingGuo/p/14297442.html
Copyright © 2011-2022 走看看