ToolTip for DataGrid Header
In this code snippet, you will see how to set the tool tip for DataGrid Header. If you have headertemplate for DataGrid, then it is very simple to set the tooltip for header. You can directly set tool tip for each colum in headertemplate. But if dont have headertemplate in your DataGrid, i.e. headers are automatically generated by DataGrid. There is not direct way to set the tooltip, in this article i will explain how to do this.
There are two ways to set the tool tip for datagrid header. One way is by writing event handler for ItemCreated event and look for header item creation. Then access the header item, after that you can set the tool tip for each item. Here is the code snippet for this method,
e.item.cells(1).Tooltip = "Age"
End Sub
Other way is by accessing the control collection of datagrid. In this method, you can directly access the DataGrid Header control in control collection and then set the tool tip for each column. This way is good at performance but it not fully foolproof. So other way in this method is, looping through each control in the control collection and then look for header itemtype. If the item is header item, then set the tool tip for each column. Here is the code snippet for both the ways,
Method1
Method2
You can write this code anywhere after you bind your datagrid. i.e once the controls are created(after itemcreated event ) in DataGrid. You can access the controls collection and set the tool tip.

浙公网安备 33010602011771号