在我的DataGridView中,我有一个DataGridViewLinkCell,我想使用标签将任意字符串传递给DGV的事件处理程序。C#无法将绑定DataGridView控件的标记传递给另一个方法
这是我的LinkCell代码:
DataGridViewLinkCell searchWU = new DataGridViewLinkCell();
searchWU.Value = "Check";
searchWU.LinkVisited = false;
searchWU.Tag = "myTag";
this.hostMgmtDataGridView[colHostViewWUAvil, this.hostMgmtDataGridView.RowCount-2] = searchWU;
然后我对DGV的事件处理程序代码:
public void hostMgmtDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewLinkCell derp = (DataGridViewLinkCell)sender;
debugLabel1.Text = derp.Tag.ToString();
}
线DataGridViewLinkCell derp = (DataGridViewLinkCell)sender;
产生以下错误:
Unable to cast object of type 'System.Windows.Forms.DataGridView' to type 'System.Windows.Forms.DataGridViewLinkCell'.
如果我将其更改为DataGridView derp = (DataGridView)sender;
我得到一个NULL参考与Object reference not set to an instance of an object.
我明白这些错误,但我不知道如何从相关的DataGridView梳理出LinkCell。
任何帮助将不胜感激 - 谢谢!
,完美的工作!谢谢! –