上一篇:用C#读取sina天气预报到wap页面(一) >>
C#版MultiSelected DataGrid
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;
}
}
}
}
下一篇:简单的多人聊天(C#.Socket). >>
相关文章:
- · C#调用父类的父类的方法
- · .NET中C#实现C/S架构下的TREEVIEW只需要输入表名,父ID,节点ID,节点名就可以得到树型结构
- · what is new in c sharp 2.0--study from msdn
- · C#设计模式之建造者(Builder)模式示例源代码
- · UBB(c#完整版)
- · c#中结构与类的区别
- · 三层结构
- · Destructors in C#
- · 链表类具有哈希表的功能
- · C#中委托,事件理解入门
- · Introduce event delegate
- · 替换以|分割的相同字符串
- · IOCP Thread Pooling in C#
- · C# struct class Differences
- · C#冒泡算法!
- · C#写的数据库操作类!
- · 快速开发vs.net+c#程序(-)
- · C#对XML操作:编辑XML文件内容
- · 用C#生成Excel文件的方法和Excel.dll组件生成的方法
- · 用C#实现Web文件的上传
- · C#编写的生成缩略图程序
- · 用一个留言簿说明C#操作XML的完全过程
- · 递归枚举排列、组合的C#源码
- · C#反编译微软MSDN2003的帮助文档,并将反编译结果保存到一个SQLSERVER数据库中
- · 用C#轻松在DOTNET中实现缩略图
- · c#中结构与类的区别
- · DES加密算法在C#下的实现
- · C#对XML操作:建立XML(3)
- · 上传图片画带阴影的水印.(C#)
- · Destructors in C#
- · 特洛伊木马服务器源代码(C#)
- · [C#]I/O完成端口的类定义和测试实例
- · 选择文件夹的对话框控件c#
- · C#实现Web文件的上传
- · 用C#实现生成PDF文档
- · 用C#实现生成PDF文档
- · 一个FTP客户端的C#代码
- · C# struct & class Differences
