I used the following three events :Click(), DoubleClick() , CurrentCellChanged() and MouseDown() and HitTestInfo to find out everything the clicked cell.
Example:
private System.Windows.Forms.DataGrid m_DataGrid;
private System.Data.DataSet m_DataSet;
private bool m_MouseEvent=false;
private System.Windows.Forms.DataGrid.HitTestInfo m_HitTestInfo;
private int m_Rows=0;
...
this.m_DataGrid.MouseDown += new System.Windows.Forms.MouseEventHandler(this.m_DataGrid_MouseDown);
this.m_DataGrid.Click += new System.EventHandler(this.m_DataGrid_Click);
this.m_DataGrid.CurrentCellChanged += new System.EventHandler(this.m_DataGrid_CurrentCellChanged);
When rendering the grid:
m_Rows=m_DataSet.Tables[0].Rows.Count;
// My overloads
private void m_DataGrid_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
m_MouseEvent=true;
m_HitTestInfo=m_DataGrid.HitTest(e.X,e.Y);
}
private void m_DataGrid_Click(object sender, System.EventArgs e)
{
if (m_MouseEvent && m_HitTestInfo.Type==System.Windows.Forms.DataGrid.HitTestType.Cell)
OnCellClick(m_HitTestInfo.Row,m_HitTestInfo.Column);
else m_MouseEvent =false;
}
private void m_DataGrid_CurrentCellChanged(object sender, System.EventArgs e)
{
if (m_MouseEvent)
OnCellClick(m_DataGrid.CurrentCell.RowNumber,m_DataGrid.CurrentCell.ColumnNumber);
m_MouseEvent=false;
}
private void OnCellClick(int vRow, int vColumn)
{
m_MouseEvent=false;
if (m_HitTestInfo.Row >= m_Rows) return;
object vCell = m_DataGrid[vRow,vColumn];
}
-obislavu-