C# DataGridView Columns – Add Link Column

Hello guys.Here is a C# DataGridView Link Column example tutorial.

DataGridView can be used to display several types of data. These different types shall correspond to different DataGridView columns.

DataGridViewLinkColumn

  • To Show links in row cells.
  • Manual data binding.
  • You can respond to user clicks on links by handling the CellContent
  • But be aware this event is distinct from the CellClick and CellMouseClick events, which normally occur whenever a user clicks anywhere in a cell.

 

using System;
using System.Collections;
using System.Windows.Forms;

namespace Link_Column
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            update();
        }

        //UPDATE DGVIEW
        public void update()
        {
            //ADD COLUMNS
            dataGridView1.ColumnCount = 4;
            dataGridView1.Columns[0].Name = "Position";
            dataGridView1.Columns[1].Name = "Team";
            dataGridView1.Columns[2].Name = "Points";
            dataGridView1.Columns[3].Name = "Games";

            //ADD ROWS
            ArrayList row = new ArrayList();
            row.Add("1");
            row.Add("Man Utd");
            row.Add("80");
            row.Add("38");
            dataGridView1.Rows.Add(row.ToArray());

            //ADD 2ND ROW
            row = new ArrayList();
            row.Add("2");
            row.Add("Man City");
            row.Add("78");
            row.Add("38");
            dataGridView1.Rows.Add(row.ToArray());

            //ADD 3rd ROW
            row = new ArrayList();
            row.Add("3");
            row.Add("Arsenal");
            row.Add("76");
            row.Add("38");
            dataGridView1.Rows.Add(row.ToArray());

            ////ADD LINK COLUMN
            DataGridViewLinkColumn link = new DataGridViewLinkColumn();
            dataGridView1.Columns.Add(link);
            link.HeaderText = "Link";
            link.Name = "http://fifa.com";
            link.Text = "Fifa";
            link.UseColumnTextForLinkValue = true;

        }
    }
}

Reminders

  • Please add a DataGridView to your form.
  • In this case I have called it datagridview1.
Share



Share an Example

Share an Example

Browse
What is the capital of Egypt? ( Cairo )