当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > C#版MultiSelected DataGrid

ASP.NET
.NET可复用TCP通信层之消息分派器组件
Asp.Net结合JS在图层上显示记录信息
.NET 2.0里使用强类型数据创建多层应用
ADO.NET Entity Framework 试水——并发
.Net开发:ADO.NET实用技巧两则
使用LINQ来简化编程的7个技巧
VC.NET扩展Windows磁盘清理工具的功能
Asp.Net页面执行流程分析
用asp.net程序备份或还原SQLServer
ASP.NET实现页面间值传递的几种方法介绍
技巧实例:如何在.NET中访问MySQL数据库
asp.net中数据校验部分的封装与应用
ASP.NET中前台javascript与后台代码调用
翻译 一些很酷的.Net技巧
ASP.NET常用的26个优化性能方法
了解VB.NET中的常量与枚举功能
.NET FileStreams将DTD插入XML文件中
Windows CE.Net下矩阵键盘开发设计详解
.Net编程接口剖析系列之比较和排序
在.NET中字符串替换的五种方法

ASP.NET 中的 C#版MultiSelected DataGrid


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 153 ::
收藏到网摘: n/a

using System;using System.Drawing;using System.Collections;using System.Windows.Forms;namespace cSharpDataGrid{ public class MyDataGrid : System.Windows.Forms.DataGrid { private ArrayList m=new ArrayList(); Array MultiSelectedIndex { get { return this.m.ToArray(typeof (int)); } } protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) { Console.WriteLine("Datagrid has hit"); Point _posDg = new Point(e.X,e.Y); System.Windows.Forms.DataGrid.HitTestInfo _hitDg =base.HitTest(_posDg); if (HitDataGrid(_hitDg)) { base.OnMouseDown(e); } base.OnMouseDown (e); } private bool HitDataGrid(DataGrid.HitTestInfo Hit) { try { switch (MyDataGrid.ModifierKeys) { case Keys.Control: if (Hit.Row>-1) { if (m.IndexOf(Hit.Row)>-1) { m.Remove(Hit.Row); this.UnSelect(Hit.Row); } else { m.Add(Hit.Row); this.Select(Hit.Row); } } return false; case Keys.Shift: if (Hit.Row>-1) { foreach (int intIndex in m) { this.UnSelect(intIndex); } m.Clear(); int _count; int _intStep; if (Hit.Row>this.CurrentRowIndex) { _intStep=1; } else { _intStep=-1; } for (_count=this.CurrentRowIndex ;_count==Hit.Row;_count+=_intStep) { m.Add(_count); this.Select(_count); } } return false; default: foreach (int _intIndex in m) { this.UnSelect(_intIndex); } m.Clear(); if (Hit.Type==DataGrid.HitTestType.RowHeader) { m.Add(Hit.Row); } return true; } } catch(System.Exception ex) { throw ex; } } }}