在 C1TrueDBGrid for WinFroms 中没有提供直接获取鼠标所在位置单元格信息的方法 GetCellFromPoint,不过在 C1TrueDBGrid for WinForms 中提供了 ColContaining 和 RowContaining 方法可获取鼠标所在位置的单元格行列值,实现代码如下:
public partial class Form3 : Form{public Form3()
{InitializeComponent();}private void Form3_Load(object sender, EventArgs e){DataTable dt = new DataTable();
dt.Columns.Add("第一列");
dt.Columns.Add("第二列");
dt.Columns.Add("第三列");
dt.Rows.Add("A1", "B1", "C1");dt.Rows.Add("A1", "B1", "C1");dt.Rows.Add("A1", "B1", "C1");dt.Rows.Add("A1", "B1", "C1");c1TrueDBGrid1.DataSource = dt;c1TrueDBGrid1.MouseMove += new MouseEventHandler(c1TrueDBGrid1_MouseMove);
}void c1TrueDBGrid1_MouseMove(object sender, MouseEventArgs e)
{C1.Win.C1TrueDBGrid.C1TrueDBGrid tdbgrid = sender as C1.Win.C1TrueDBGrid.C1TrueDBGrid;// 获取鼠标所在位置的单元格
Point p = tdbgrid.PointToClient(Control.MousePosition);Point curRowCol = new Point(tdbgrid.ColContaining(p.X), tdbgrid.RowContaining(p.Y));
toolStripStatusLabel1.Text = string.Format("({0},{1})",curRowCol.Y,curRowCol.X);
}}
运行截图: