首先在dataGridView里面添加datagridviewlinkcolumn列
然后選擇dataGridView的CellContentClick事件:
如下:
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 2)
{
System.Diagnostics.Process.Start("iexplore.exe", "http://social.microsoft.com/Forums/zh-CN/2212/threads");
//this.dataGridView2.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
}
}
在綁定中可以設置在dataGridView中顯示的文本,即text屬性即可,然后在單擊事件中System.Diagnostics.Process.Start,傳入的網址也是根據此行的相關數據得到,
可以用以下方法獲取
ds.Tables[0].Rows[e.RowIndex]["ID"].ToString()
這樣但點擊此鏈接的時候就會出現相關的網頁。