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

ASP.NET
ASP.NET Tips1---合并多个字段值
如何 动态编译自己写的代码
用.NET设计一个新的课程
.NET策略是如何创建起来的
C#事件机制归纳上
IL系列文章之四ArrayinIL续
C#事件机制归纳下
我的ASP.net学习历程调用类库函库的简单加密方法
vb 常量声明
XMLWebServices底层结构
快速高效创建你的子窗口
深度和广度优先分油问题(C#实现)
水晶报表中子报表的数据绑定问题
用C#编写获取远程IP,MAC的方法
利用"委托"实现对象实例按"多字段嵌套"排序
.NET数值类型的精度
接受改变:从VB程序员到VB.Net程序员
掌握 C#
自定义 StringTable 的自动完成功能 (C# API : SHAutoComplete)
自己写的一个图表控件

ASP.NET 中的 C#版MultiSelected DataGrid


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