How to get LinkLabel Control from DataGridview

70 Views Asked by At

How to get LinkLabel control from DataGridview in Windows Forms application? Below is the code I am writing, able to get the value but not able to get the LinkLabel control.

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    string name = this.dataGridView1.Rows[e.RowIndex].Cells["Name"].ToString();
    LinkLabel label; //Here I need to get the linklabel control same way like value 
}
1

There are 1 best solutions below

0
Ken On

Usually, your control like LinkLabel myLinkLabel is a control that has been added to the Winform using the designer.

So, you would set myLinkLabel.Text = "some string" or a variable.

Or you could dynamically add the control to your form:

LinkLabel myLinkLabel = new LinkLabel();
myLinkLabel.Text = "some string";
// use other properties of myLinkLabel to set position, font, color, etc.
Controls.Add(myLinkLabel);