Home > DeveloperSection > Forums > Add ViewLink DataGridView in C#
Alex Leblois
Alex Leblois

Total Post:67

Points:471
Posted on    June-15-2013 5:02 AM

 C# C# 
Ratings:


 1 Reply(s)
 1125  View(s)
Rate this:
Hi developers,

How can I add a viewlink in datagridview using C#

Thanks in advance.


Sumit Kesarwani

Total Post:378

Points:2694
Posted on    June-15-2013 7:32 AM

Hi Alex,

You can use this code:

using System;

using System.Data;

using System.Windows.Forms;

using System.Data.SqlClient;

using System.Drawing;

 

namespace WindowsApplication1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            dataGridView1.ColumnCount = 3;

            dataGridView1.Columns[0].Name = "Product ID";

            dataGridView1.Columns[1].Name = "Product Name";

            dataGridView1.Columns[2].Name = "Product Price";

 

            string[] row = new string[] { "1", "Product 1", "1000" };

            dataGridView1.Rows.Add(row);

            row = new string[] { "2", "Product 2", "2000" };

            dataGridView1.Rows.Add(row);

            row = new string[] { "3", "Product 3", "3000" };

            dataGridView1.Rows.Add(row);

            row = new string[] { "4", "Product 4", "4000" };

            dataGridView1.Rows.Add(row);

 

            DataGridViewLinkColumn lnk = new DataGridViewLinkColumn();

            dataGridView1.Columns.Add(lnk);

            lnk.HeaderText = "Link Data";

            lnk.Name = "http://www.mindstick.com";

            lnk.Text = "http://www.mindstick.com";

            lnk.UseColumnTextForLinkValue = true;

        }

    }

}


Don't want to miss updates? Please click the below button!

Follow MindStick