views:

369

answers:

2

I have a Winforms app that has a DataGridView that is databound at runtime. One of the columns contains mostly just text but some of it's cells are populated with url's that I would like to make clickable. How can I can I tell the DataGridView that if the value in the cell looks like a valid url ie. begins with "http" or something similiar make it a clickable link?

+1  A: 

Put a user control there that has multiple child controls like link, textbox or combobox but only make one of them visible at any time.

Sheng Jiang 蒋晟
A: 

A solution that did the trick was to add the following code to the CellClick event of the DataGridView.

if (this.dataGridViewName[e.ColumnIndex, e.RowIndex].Value.ToString().StartsWith("http"))
        {
            Process p = new Process();
            p.StartInfo.FileName = Utilities.getDefaultBrowser();
            p.StartInfo.Arguments = this.dataGridViewName[e.ColumnIndex, e.RowIndex].Value.ToString();
            p.Start();
        }

I got the code to launch the browser as well as the getDefaultBrowser() code from a very helpful article here

TooFat