是否可以让DataGridViewLinkCell显示类似搜索的内容,但链接为http://google.com?
我希望DataGridView不会被实际的链接所困扰.
解决方法:
private void Form1_Load(object sender, EventArgs e)
{
DataGridViewLinkColumn c = new DataGridViewLinkColumn();
dataGridView1.Columns.Add(c);
dataGridView1.Rows.Add();
dataGridView1.Rows[0].Cells[0].Value = "search";
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
switch (dataGridView1[e.ColumnIndex,e.RowIndex].Value.ToString())
{
case ("search"):
Process.Start("http://www.google.com");
break;
}
}
或这样,避免出现大开关情况:
class customcolumn : System.Windows.Forms.DataGridViewLinkColumn
{
public Dictionary<int, string> urls = new Dictionary<int, string>();
}
private void Form1_Load(object sender, EventArgs e)
{
int row_index = 0;
int column_index = 0;
customcolumn c = new customcolumn();
dataGridView1.Columns.Add(c);
dataGridView1.Rows.Add();
//Add Link-name here:
dataGridView1.Rows[row_index].Cells[column_index].Value = "search";
//Add Link here:
((customcolumn)(dataGridView1.Columns[column_index])).urls.Add(row_index, "http://www.google.com");
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
foreach (KeyValuePair<int, string> url in ((customcolumn)(dataGridView1.Columns[e.ColumnIndex])).urls)
{
if (url.Key == e.RowIndex)
{
Process.Start(url.Value);
break;
}
}
}