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?
将用户控件放在那里,该控件具有多个子控件,例如链接,文本框或组合框,但在任何时候都只能显示其中的一个。
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.