Reputation: 39
I have winform in c# that contains datagridview that display table from my database. One of the column is hyperlink data type. But the link doesn't seem to display correctly. for example http://google.com display as #http://google.com# on the column. The question is: How do I remove # from my hyperlink column? How can I make the link accessible? I mean, whenever I click, the link opens in a browser. Here is the example pic
Upvotes: -1
Views: 172
Reputation: 5986
You need to set the link column separately.
I write a working code example, and you could have a look.
Code:
private void Form1_Load(object sender, EventArgs e)
{
DataGridViewLinkColumn col1 = new DataGridViewLinkColumn();
dataGridView1.Columns.Add(col1);
dataGridView1.Columns[0].Name = "Links";
DataGridViewRow dgvr = new DataGridViewRow();
dgvr.CreateCells(dataGridView1);
DataGridViewCell linkCell = new DataGridViewLinkCell();
linkCell.Value = @"http:\\www.google.com";
dgvr.Cells[0] = linkCell;
dataGridView1.Rows.Add(dgvr);
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex] is DataGridViewLinkColumn && !(e.RowIndex == -1))
{
Process.Start(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
}
}
Upvotes: 0