You can display additional information about cell or description of cell content to user with the help of tooltips.You can add ToolTips to Individual Cells of Datagridview control in vb.net.
You can also disable the display of cell-level ToolTips by setting the DataGridView.ShowCellToolTips property to false.
Example
In following example we will set the tooltips on the different cells of datagridview control. This example requires a DataGridView control named dataGridView1 that contains a column named ‘Reputation’ for displaying string values of asterisk (“*”) symbols(see above picture). We use the CellFormatting event of the DataGridView control for doing it.
private sub AddTooltipsCell() BindDataGrid() AddTooltips() End Sub
First we will bind the DataGridView with data:
Private Sub BindDataGrid() DataGridView1.Rows.Add() DataGridView1.Rows(0).Cells(0).Value = 1 DataGridView1.Rows(0).Cells(1).Value = "Ankur" DataGridView1.Rows(0).Cells(2).Value = "*" DataGridView1.Rows.Add() DataGridView1.Rows(1).Cells(0).Value = 2 DataGridView1.Rows(1).Cells(1).Value = "John" DataGridView1.Rows(1).Cells(2).Value = "* *" DataGridView1.Rows.Add() DataGridView1.Rows(2).Cells(0).Value = 3 DataGridView1.Rows(2).Cells(1).Value = "Smith" DataGridView1.Rows(2).Cells(2).Value = "* * *" End Sub
And now We will set the tooltips to every cell of ‘Reputation’ column.
Private Sub AddTooltips() For Each drow As DataGridViewRow In DataGridView1.Rows Dim dgvCell As DataGridViewCell dgvCell = drow.Cells(2) If (dgvCell.Value.Equals("*")) Then dgvCell.ToolTipText = "Bronze" ElseIf (dgvCell.Value.Equals("* *")) Then dgvCell.ToolTipText = "Silver" ElseIf (dgvCell.Value.Equals("* * *")) Then dgvCell.ToolTipText = "Gold" End If Next End Sub