ToolTip over a DataGridView row?

G

gregarican

I have a standard VC# 2005 DataGridView showing a group of records
coming from a table. Currently I have a CellMouseDoubleClick event
popping up a MessageBox which pulls a timestamp of the transaction
from a related table based on the row in the DataGridView that the
double click was registered against. I didn't want to add the extra
column with this timestamp info into the DataGridView since it's not
always needed by the enduser.

Rather than this double click mechanism I would like the ability to
create a mouse over event that would present this timestamp in a
bubble to the enduser. If they hover the mouse over a cell then that
row is fed into the method I have that presents the timestamp.
Checking out the ToolTip control it appears as if I can just define
the text to be presented if the enduser hovers their mouse over the
column headings. Not the cell contents themselves.

Am I missing something here? Even a basic example would be
appreciated, since I'm not looking to define the text explicitly in a
control property. I need to programmatically define it by passing the
DataGridView row's values into a method.

Thanks!
 
G

gregarican

I have a standard VC# 2005 DataGridView showing a group of records
coming from a table. Currently I have a CellMouseDoubleClick event
popping up a MessageBox which pulls a timestamp of the transaction
from a related table based on the row in the DataGridView that the
double click was registered against. I didn't want to add the extra
column with this timestamp info into the DataGridView since it's not
always needed by the enduser.

Rather than this double click mechanism I would like the ability to
create a mouse over event that would present this timestamp in a
bubble to the enduser. If they hover the mouse over a cell then that
row is fed into the method I have that presents the timestamp.
Checking out the ToolTip control it appears as if I can just define
the text to be presented if the enduser hovers their mouse over the
column headings. Not the cell contents themselves.

Am I missing something here? Even a basic example would be
appreciated, since I'm not looking to define the text explicitly in a
control property. I need to programmatically define it by passing the
DataGridView row's values into a method.

Thanks!

Please disregard. I googled some more through the group postings and
found my answer!
 
N

Nicholas Paldino [.NET/C# MVP]

Care to show your link to the answer so others might benefit? =)
 
C

ClayB

For a Windows Forms DataGridView, you can handle the
dataGridView1.CellToolTipTextNeeded event and dynamically provide the
tip text there.

dataGridView1.CellToolTipTextNeeded += new
DataGridViewCellToolTipTextNeededEventHandler(dataGridView1_CellToolTipTextNeeded);


void dataGridView1_CellToolTipTextNeeded(object sender,
DataGridViewCellToolTipTextNeededEventArgs e)
{
e.ToolTipText = string.Format("tip for row {0}, col {1}",
e.RowIndex, e.ColumnIndex);
}

========================
Clay Burch
Syncfusion, Inc.
 
G

gregarican

Care to show your link to the answer so others might benefit? =)

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




Please disregard. I googled some more through the group postings and
found my answer!- Hide quoted text -

- Show quoted text -

What I did was set the ShowCellToolTips DataGridView property to False
in the design view. By default it's set to True. Then I went in and
defined the CellMouseEnter event for the DataGridView. Here's a
snippet, where dgv_Lookup is a DataGridView instance, and ttLookup is
a ToolTip instance:

dgvLookup_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
// Ignore any mouse hovers other than those at column 7.
Also ignore any invalid RowIndex values.
if (e.RowIndex != -1 && e.ColumnIndex == 7)
{
DataTable showTable = new DataTable();
DataRow showRow;
showRow = showTable.NewRow();
dsTableAdapters.taTrxTableAdapter taTrxTable = new
dsTableAdapters.taTrxTableAdapter();
showTable =
taTrxTable.GetDataById(this.dgvLookup.Rows[e.RowIndex].Cells[0].Value.ToString());

// Just fetch the first row of the result set.
showRow = showTable.Rows[0];
this.dgvLookup.CurrentCell.ToolTipText =
showRow["loggedTime"].ToString();

this.ttLookup.Show(showRow["loggedTime"].ToString(), this.dgvLookup);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top