c# - Hyperlink cell in Winforms DataGridView -


i have datagridview following data.

contacttype        |        contact ------------------------------------ phone              |       894356458 email              |     xyz@abc.com 

here, need display data "xyz@abc.com" hyperlink, tooltip "click send email". number data "894356458" should not have hyperlink.

any ideas???

tia!

the datagridview has column type this, datagridviewlinkcolumn.

you need databind column type manually, datapropertyname sets column bind in grid's datasource:

datagridviewlinkcolumn col = new datagridviewlinkcolumn(); col.datapropertyname = "contact"; col.name = "contact";        datagridview1.columns.add(col); 

you want hide autogenerated text column comes contact property of grid.

also, datagridviewbuttoncolumn need handle user interaction responding cellcontentclick event.


to change cell values not hyperlinks plain text need replace link cell type textbox cell. in example below i've done during databindingcomplete event:

void datagridview1_databindingcomplete(object sender, datagridviewbindingcompleteeventargs e) {     foreach (datagridviewrow r in datagridview1.rows)     {         if (!system.uri.iswellformeduristring(r.cells["contact"].value.tostring(), urikind.absolute))         {             r.cells["contact"] = new datagridviewtextboxcell();         }     } } 

you can other direction, changing datagridviewtextboxcell datagridviewlinkcell suggest second since need apply changes apply links every cell.

this have advantage though not need hide autogenerated column, may suit best.

void datagridview1_databindingcomplete(object sender, datagridviewbindingcompleteeventargs e) {     foreach (datagridviewrow r in datagridview1.rows)     {         if (system.uri.iswellformeduristring(r.cells["contact"].value.tostring(), urikind.absolute))         {             r.cells["contact"] = new datagridviewlinkcell();             // note if want different link colour example must go here             datagridviewlinkcell c = r.cells["contact"] datagridviewlinkcell;             c.linkcolor = color.green;         }     } } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -