簡體   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