鼠标在FlexGrid中移动过程中,我们可以在MouseMove中计算出鼠标所在的行、列值:
  1.       
    private void _flex_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
            {
                int row, col;
                double rowHeight, colWidth;
    
                row = -1;
                col = -1;
                rowHeight = 0;
                colWidth = 0;
    
                Point p = e.GetPosition(_flex);
    
                for (int r = 0; r < _flex.Rows.Count; r++)
                {
                    rowHeight += _flex.Rows[r].ActualHeight;
                    if (p.Y < rowHeight)
                    {
                        row = r;
                        break;
                    }
                }
    
                colWidth = _flex.RowHeaders.DesiredSize.Width;
                for (int c = 0; c < _flex.Rows.Count; c++)
                {
                    colWidth += _flex.Columns[c].ActualWidth;
                    if (p.X < colWidth)
                    {
                        col = c;
                        break;
                    }
                }
    
                this.label1.Content = string.Format("({0},{1})", row, col);
            }
    复制代码