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

ASP.NET
ASP.NET应用程序设计的10大技巧
asp.net开发与web标准的冲突问题
总结:ADO.NET中容易混淆的概念
ASP.NET数据库编程入门
ASP.Net网络数据库:连接到数据库
ASP.Net之C#中的异常处理
在C++中使用Lambda函数提高代码性能
从零开始学习jQuery (一) 开天辟地入门篇
.Net中的 XmlReader 与 XmlWriter 解析
ASP.NET安全问题--创建安全的Web应用程序
从零开始学习jQuery (二) 万能的选择器
ASP.NET开发必须养成的编程习惯
ASP.NET应用XML技术实现Web报表打印
ASP.NET实现静态的TreeView控件导航
数据结构与算法:C#语言描述 目录
ASP.NET创建XML Web服务全接触
使.NET命名空间符合标准
ASP.Net获得新浪天气预报几种方式总结
.Net技术开发中两个“属性”引起的歧异
.Net课堂:ASP.NET常用的优化性能方法

ASP.NET 中的 C#版MultiSelected DataGrid


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 150 ::
收藏到网摘: 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; } } }}