I have a datagridview with the following data.
ContactType | Contact
------------------------------------
Phone | 894356458
Email | xyz@abc.com
Here, I need to display the data “xyz@abc.com” as a hyperlink, with a tooltip “Click to send email”. The number data “894356458” should not have a hyperlink.
Any ideas???
TIA!
The
DataGridViewhas a column type for this, theDataGridViewLinkColumn.You need to databind this column type manually, where
DataPropertyNamesets the column to bind to in the grid’s datasource:You will also want to hide the autogenerated text column that comes from the Contact property of the grid.
Also, as with the
DataGridViewButtonColumnyou need to handle the user interaction yourself by responding to theCellContentClickevent.To then change cell values that are not hyperlinks to plain text you need to replace the link cell type with the textbox cell. In the example below I’ve done this during the
DataBindingCompleteevent:You can also do this from the other direction, changing the
DataGridViewTextBoxCellto aDataGridViewLinkCellI suggest this second since you will need to apply any changes that apply to all links to every cell.This does have the advantage though that you will not then need to hide the autogenerated column, so may suit you best.