C#版MultiSelected DataGrid

王朝c#·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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;

}

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航