0

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 
}
  • What LinkLabel? You expect the cell of the DataGridview to be one? Or do you have another control on your form that is bound to the same data? Or do you have another Control on your form that is bound to a variable or has a name equal to the one you read from the DataGridView? Or .... Please be more specific in what you want or need. – Ralf Oct 06 '22 at 08:37
  • I have Windows Forms application, where I am using a LinkLabel control inside DataGridView. I want this control to add Link property to it dynamically for each DataGridViewRow. – minakshi singh Oct 06 '22 at 10:23
  • A grid has columns, rows, cells and cells sometimes show an editor that can be a standard control. But if you say "I am using a LinkLabel control inside DataGridView" then you do something that isn't possible out of the box and you need to show what you have done to get there. – Ralf Oct 06 '22 at 10:34

1 Answers1

0

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);
Ken
  • 526
  • 6
  • 13