Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid Events

Status
Not open for further replies.

apc2003

Programmer
Aug 29, 2003
54
GB
Using a DataGrid to display some data, I need to be able to set a Double Click event on a specific item within the DataGrid much like using a ListView!

The Click events on the DataGrid only work on the Title or left side bar, not on the cells.

Any Help would be great...

Thanks in advance...

 
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-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top