Consider my DataGridView as above, when mouse hovers over a cell in NameID field, based on the value present in cell-should display the tooltip. For example: As shown above(Image), when mouse hovers over the value '3' in NameID field - 'ABC' is shown as tooltip, similarly for '1' it should show 'DBC' and so on.
Below is code I have written in C#-Winforms, based on article found in this link: https://msdn.microsoft.com/en-us/library/2249cf0a(v=vs.110).aspx
But This doesn't seem work, Even the property ShowCellToolTips is made True.
void ToolTip1(object sender,DataGridViewCellFormattingEventArgs e)
{
if ((e.ColumnIndex == this.dataGridView1.Columns["NameID"].Index)
&& e.Value != null)
{
DataGridViewCell cell =
this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
if (e.Value.Equals("0"))
{
cell.ToolTipText = "Please update NameID as required, To know more click Help icon";
}
else if (e.Value.Equals("1"))
{
cell.ToolTipText = "DBC";
}
else if (e.Value.Equals("2"))
{
cell.ToolTipText = "XYZ";
}
else if (e.Value.Equals("3"))
{
cell.ToolTipText = "ABC";
}
}
}
How can I achieve this? how to make this work?
You can just use CellMouseEnter
event like this:
private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
if ((e.ColumnIndex == this.dataGridView1.Columns["NameID"].Index))
{
//column name
DataGridViewCell cell =
this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
//column id
DataGridViewCell cell1 =
this.dataGridView1.Rows[e.RowIndex].Cells["NameID"];
cell.ToolTipText = "DBC";
if (cell1.Equals("0"))
{
cell.ToolTipText = "Please update NameID as required, To know more click Help icon";
}
else if (cell1.Equals("1"))
{
cell.ToolTipText = "DBC";
}
else if (cell1.Equals("2"))
{
cell.ToolTipText = "XYZ";
}
else if (cell1.Equals("3"))
{
cell.ToolTipText = "ABC";
}
}
}
Here you find more
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With