在我的项目中,我正在填充dataGridView
from dataSet
(绑定DataGridView
to DataSet
)。第一列dataGridView
必须是LinkLabels
我试图在下面的代码中获得的。
dgvMain.DataSorce = ds.Tables[0];
我试过了:(不工作)
DataGridViewLinkCell lnkCell = new DataGridViewLinkCell();
foreach (DataGridViewRow row in dgvMain.Rows)
{
row.Cells[0] = lnkCell; // (ERROR) Cell provided already belongs to a grid. This operation is not valid.
}
也试过
for (int intCount = 0; intCount < dgvMain.Rows.Count; intCount++)
{
dgvMain.Rows[intCount].Cells[0] = lnkCell; // (ERROR) Cell provided already belongs to a grid. This operation is not valid.
}
上面的尝试只是添加linkLabel
到第一个单元格而不是该列中的所有单元格
当我调试我的代码时,我得出的结论是,在添加linkLabel
到第一个单元格之后,我在上面的代码中提到了异常错误,这正在制作代码不能正常运行。
请给我任何建议,我该怎么办?
编辑:虽然这不是正确的方法,但我Linklabel
通过编写以下代码使列单元格看起来像:
foreach (DataGridViewRow row in dgvMain.Rows)
{
row.Cells[1].Style.Font = new Font("Consolas", 9F, FontStyle.Underline);
row.Cells[1].Style.ForeColor = Color.Blue;
}
现在的问题是我无法将Hand
光标添加到唯一的列单元格(对于 LinkLabels 可见)。有没有办法实现它?(我需要回答这两个问题,主要是第一个)。