在冻结的行或列中,如何实现在右键单击处的单元格被选中
问题描述:如题问题解答:Spread 提供MouseDown 事件用于获取鼠标点击事件,在事件中可以通过HitTestInformation 类获取当前操作的单元格。
关键代码:
private void Form1_Load(object sender, EventArgs e)
{
this.fpSpread1.Sheets.FrozenRowCount = 1;
this.fpSpread1.MouseDown += newMouseEventHandler(fpSpread1_MouseDown);
}
private void fpSpread1_MouseDown(object sender, MouseEventArgs e)
{
//获取当前鼠标点击单元格信息
HitTestInformationhtinfo = this.fpSpread1.HitTest(e.X, e.Y);
int curRow = htinfo.ViewportInfo.Row;
//判断是否点击在冻结行
if (e.Button == System.Windows.Forms.MouseButtons.Right && curRow == 0)
{
FarPoint.Win.Spread.HitTestInformation hitTest = this.fpSpread1.HitTest(e.X, e.Y);
int row = hitTest.ViewportInfo.Row; int col = hitTest.ViewportInfo.Column;
this.fpSpread1.Sheets.SetActiveCell(row, col);
}
}
示例下载:点击下载
页:
[1]