简体   繁体   中英

Can't display linklabel text in a datagridviewlinkcolumn

I have a little but pretty annoying problem:

I have created a datagridview and bound it to a datasource. Then now I want to add a column which will display links for the user to click. In order to do that i added a datagridviewlinkcolumn. For each rows of the datagrid I set the value of the cell in that column to the text i want to be displayed. But it shows nothing. All the datagridlinkcolumn is filled with "blank text".

Here is my code:

DataGridViewLinkColumn dgvColDeletion = new DataGridViewLinkColumn();
dgvColDeletion.Name = "Deletion";
dgvColDeletion.HeaderText = "";
dgvColDeletion.ReadOnly = false;
dgvTrainings.Columns.Add(dgvColDeletion);

foreach (DataGridViewRow row in dgvTrainings.Rows)
{
     row.Cells["Deletion"].Value = "Delete";
}
dgvColDeletion.Update();
dgvTrainings.Update();

I also tried with setting directly linklabels or datagridviwlinkcells, but the problem still remains.

I cant get any clue why this isn't working.

Any help will be very much appreciated, thanks.

To display the same link text for every cell, set the UseColumnTextForLinkValue property to true and set the Text property to the desired link text.

DataGridViewLinkColumn dgvColDeletion = new DataGridViewLinkColumn();
dgvColDeletion.UseColumnTextForLinkValue = true;
dgvColDeletion.Text = "Delete";

Try this. I hope this will helps to you.

DataGridViewLinkColumn dgvColDeletion = new DataGridViewLinkColumn();  


dgvColDeletion.UseColumnTextForLinkValue = true;<br/>
                dgvColDeletion.Text = "Delete";<br/>
                dgvColDeletion.ActiveLinkColor = Color.White;<br/>
                dgvColDeletion.LinkBehavior = LinkBehavior.SystemDefault;<br/>
                dgvColDeletion.LinkColor = Color.Blue;<br/>
                dgvColDeletion.TrackVisitedState = true;<br/>
                dgvColDeletion.VisitedLinkColor = Color.YellowGreen;<br/>
                dgvColDeletion.Name = "Delete";<br/>
                dgvColDeletion.HeaderText = "Delete";<br/>
                if (grid_shared.Columns.Contains("Delete") == false)<br/>
                {<br/>
                    dgvColDeletion.Columns.Add(lnkDelete);<br/>
                    dgvColDeletion.Columns["Delete"].Width = 40;<br/>
                }<br/>

Happy coding..:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM