Search This Blog

Thursday, March 6, 2014

Change DataGridView column to Hyperlink Runtime

C# > DataGridViewDataGridViewLinkCell

Example: Change DataGridView column to Hyperlink Runtime


foreach (DataGridViewRow r in dgv.Rows)
{
DataGridViewLinkCell lc = new DataGridViewLinkCell();
       lc.Value = r.Cells[1].Value;
       dgv[1, r.Index] = lc;
}


private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1)
              return;
if (dgv.Rows[e.RowIndex].Cells[e.ColumnIndex] is DataGridViewLinkCell)
       {
             string link = "http://www...";
             if(e.ColumnIndex == 1)
                System.Diagnostics.Process.Start(link  +                          dgv.Rows[e.RowIndex].Cells[4].Value as string);
       }

}