在GridControl中的GridView属性栏中注册MouseDown、MouseMove以及MouseUp事件,在将timer计时器添加到GridControl中,并实现它的Tick事件。
另外:将GridView的OperationBehavior中的Editorable设为false(不可编辑),将OperationSelection中的MultiSelect设为true。
#region select many
private int GetRowAt(GridView view, int x, int y)
{
return view.CalcHitInfo(new Point(x, y)).RowHandle;
}
//鼠标按下触发gdvPO_MouseDown事件
private void gdvLotData_MouseDown(object sender, MouseEventArgs e)
{
StartRowHandle = GetRowAt(sender as GridView, e.X, e.Y);
}
//鼠标松开触发gdvPO_MouseDown事件
private void gdvLotData_MouseUp(object sender, MouseEventArgs e)
{
StartRowHandle = -1;
CurrentRowHandle = -1;
timer1.Stop();
}
private void SelectRows(GridView view, int startRow, int endRow)
{
if (startRow > -1 && endRow > -1)
{
view.BeginSelection();
view.ClearSelection();
view.SelectRange(startRow, endRow);
view.EndSelection();
}
}
private void gdvLotData_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
GridView view = sender as GridView;
GridViewInfo info = view.GetViewInfo() as GridViewInfo;
GridHitInfo hi = view.CalcHitInfo(e.Location);
int newRowHandle = GetRowAt(sender as GridView, e.X, e.Y);
if (CurrentRowHandle != newRowHandle)
{
CurrentRowHandle = newRowHandle;
SelectRows(sender as GridView, StartRowHandle, CurrentRowHandle);
}
if (info.RowsInfo.Count < 1)
{
return;
}
if (info.RowsInfo.Count >= 2 && info.RowsInfo[info.RowsInfo.Count - 2].RowHandle == hi.RowHandle)
{
scrollDown = true;
if (!timer1.Enabled)
timer1.Start();
}
else
{
if (info.RowsInfo[0].RowHandle == hi.RowHandle)
{
scrollDown = false;
if (!timer1.Enabled)
timer1.Start();
}
else
timer1.Stop();
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (scrollDown)
{
gdvLotData.TopRowIndex++;
}
else
{
gdvLotData.TopRowIndex--;
}
Point ee = gdcLotData.PointToClient(MousePosition);
int newRowHandle = GetRowAt(gdvLotData, ee.X, ee.Y);
if (CurrentRowHandle != newRowHandle)
{
CurrentRowHandle = newRowHandle;
SelectRows(gdvLotData, StartRowHandle, CurrentRowHandle);
}
}
#endregion
(子窗口)获取选中项的某列的值并用数组接收,在将该数组传入父窗口:
private void btnOK_Click(object sender, EventArgs e)
{
try
{
GlobalVariable.gaSelectPOID.Clear();
int[] iaPOs = gdvLotData.GetSelectedRows();
if (iaPOs.Length < 1)
{
CommonFunction.ShowMsgBox("请选择一条或多条参数");//ToDo: Multi-Language
return;
}
int[] iaRAWID = new int[iaPOs.Length];//+2
for (int i = 0; i < iaPOs.Length; i++)
{
iaRAWID[i] = Convert.ToInt32(gdvLotData.GetRowCellValue(iaPOs[i], "RAW_ID"));
}
//saPARA_ID[iaPOs.Length] = cboModelVer.EditValue.ToString();
//saPARA_ID[iaPOs.Length + 1] = "EVENT";
if (iaRAWID.Length > 0)
{
if (this.Owner is frmFDCTranMTSpecCalculate)
{
((frmFDCTranMTSpecCalculate)this.Owner).LotDataRawIDs = iaRAWID;
}
this.Close();
}
}
catch (Exception ex)
{
CommonFunction.ShowMsgBox("frmAPSReleaseWO.btnSelect_Click()\n" + ex.Message);
}
}
(父窗口)设置接收子窗口传来的数组:
private int[] iaLotDataRawIDs;
public int[] LotDataRawIDs
{
set
{
iaLotDataRawIDs = value;
}
}
验证是否成功接收(在父窗口中添加一个label和button),点击button将数组拼成字符串显示在label中:
private void simpleButton1_Click(object sender, EventArgs e)
{
for (int i = 0; i < iaLotDataRawIDs.Length; i++)
{
this.labelControl13.Text += iaLotDataRawIDs[i].ToString() + ";";
}
}
=================
GridView设置表格不可编辑: