我正在使用winforms API和C#创建一个应用程序。
我有gridview,有些行有一个与行关联的对象。该对象存储在Tag
属性中,如此
var tagObj = new AdditionalInfoPhoneActivations();
rowInfo.Tag = tagObj;
radGridView1.Rows.Add(rowInfo);
以下是我尝试访问无效的标记属性
void radGridView1_CommandCellClick(object sender, EventArgs e) {
var tagObj = new AdditionalInfoPhoneActivations();
var x = (sender as CellFormattingEventArgs);
tagObj = e.CellElement.Tag;
Common.Alert("You ordered " + tagObj.serialNumber + " " + tagObj.saleType);
}
这是我遇到的错误
Error 2 'System.EventArgs' does not contain a definition for 'CellElement' and no extension method 'CellElement' accepting a first argument of type 'System.EventArgs' could be found (are you missing a using directive or an assembly reference?) C:\Users\User\C# Projects\RM\RM\Register.cs 175 24 RM
答案 0 :(得分:1)
你正在施放错误的类型。此外,您最有可能必须访问该单元所属的行(RowElement),并将Tag
属性(这是object
并且可以存储任何内容)转换回该类型您最初存储在其中的对象。
var cell = (sender as GridCommandCellElement);
if (cell != null)
{
var myTag = (AdditionalInfoPhoneActivations)cell.RowElement.RowInfo.Tag;
}