繁体   English   中英

如何根据单元格的值在运行时设置DataGridViewColumn数据类型?

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

我有一个Winforms应用程序,该应用程序具有在运行时进行数据绑定的DataGridView。 其中一列仅包含文本,但其中某些单元格填充有我希望使其可点击的url。 我怎样才能告诉DataGridView单元格中的值看起来像一个有效的URL,即。 以“ http”开头或类似的东西使它成为可点击的链接?

将用户控件放在那里,该控件具有多个子控件,例如链接,文本框或组合框,但在任何时候都只能显示其中的一个。

达到目的的解决方案是将以下代码添加到DataGridView的CellClick事件中。

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();
        }

我从这里非常有用的文章中获得了启动浏览器的代码以及getDefaultBrowser()代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM