简体   繁体   English

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

[英]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. 我有一个Winforms应用程序,该应用程序具有在运行时进行数据绑定的DataGridView。 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. 其中一列仅包含文本,但其中某些单元格填充有我希望使其可点击的url。 How can I can I tell the DataGridView that if the value in the cell looks like a valid url ie. 我怎样才能告诉DataGridView单元格中的值看起来像一个有效的URL,即。 begins with "http" or something similiar make it a clickable link? 以“ http”开头或类似的东西使它成为可点击的链接?

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

A solution that did the trick was to add the following code to the CellClick event of the DataGridView. 达到目的的解决方案是将以下代码添加到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();
        }

I got the code to launch the browser as well as the getDefaultBrowser() code from a very helpful article here 我从这里非常有用的文章中获得了启动浏览器的代码以及getDefaultBrowser()代码。

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

相关问题 如何根据单元格中的可变值设置datagrid行的背景 - How to set datagrid row's background based on variably value in cell 如何在C#中将Excel单元格的值类型设置为Text? - How to set a Excel cell's value type to Text in C#? 如何将DataGridViewColumn单元格设置为不可选择? - how to set a DataGridViewColumn cells to unselectable? 如何设置自定义DataGridViewColumn的自定义EditingControl的属性 - How to set properties of custom EditingControl of a custom DataGridViewColumn 如何检查用户是否为DataGridViewColumn输入了唯一值? - How to check that the user entered a unique value for a DataGridViewColumn? 如何根据属性的运行时类型动态选择验证器? - How to dynamically select a validator based on property's runtime type? 根据列数据类型更改DataGrid的单元格值 - Change cell value of DataGrid based on column data type 如何基于下拉列表的选择动态设置网格视图中单元格的值? - how to dynamically set the value of a cell in gridview based on selection of dropdownlist? 如何知道用户在运行时在文本框中输入的值的数据类型? - How to know the data type of value entered by user at runtime in textbox? 基于目标 class 类型的数据运行时分配 - Runtime assignment of data based on target class type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM