在我的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。
任何幫助將不勝感激 - 謝謝!
,完美的工作!謝謝! –