开发者

How to set DataGridViewColumn data Type at RunTime based on the cell's value?

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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜