The tip shows how to create, for example, on the cell of a DataGridView with specialized content a tooltip whose content in turn from the field of a data table is read. I often had in a data-bound DataGridView in case that is shown in a column a short cut. In explaining the tips I suppose it was this example: The DGV column contains the ISO abbreviation for the European currencies. The tooltip for this column is always for this text so there is a data table that contains both-both ISO currency code as well as text dt.
Then you reach the "purpose" with the following procedure:
Code:
Private Sub DatagridView1_CellMouseEnter (ByVal sender As Object, _
ByVal e As DataGridViewCellEventArgs) _
Handles dataGridView1. CellMouseEnter
Dim dgv As DataGridView = CType (sender, DataGridView)
E. If RowIndex <= 0 Then Exit Sub
E. If columnIndex <0 OrElse e. columnIndex> getDGVColsVisible (dataGridView1) Then Exit Sub
Dim s As String = dgv. Columns (e. columnIndex). Name
If n <> "Waehrungssymbol" Then Exit Sub
Dim c As DataGridView dgv = cell. Rows (e. RowIndex). Cells (e. columnIndex)
With c
If Not IsDBNull (. Value) Then
Dim As String = CVAL. Value
bsWaehr. Position = bsWaehr. Find ("ISOKz" CVAL)
Dim dd As DataRowView = bsWaehr. Current
. ToolTipText = dd ("dtWaehrungstext)
End If
End With
End Sub
It is tested on which column of the DGV is the mouse and whether the DGV column for which the tooltip is to be produced, including one to the visible (there are the auxiliary function getDGVColsVisible, see below).
In the example, the column "Waehrungssymbol" the ISO code, which in turn is stored in the data table under field ISOKz. The text to be shown as a tooltip is stored in field dtWaehrungstext. By means of the Binding Source "bsWaehr" is searched each row that contains the code in the current cell in the DGV. Then simply read only from the corresponding record for the German currency, the value assigned to the text and tooltip.
Bookmarks