我有一个子类的按钮与一对夫妇性质对象倾斜访问类的属性
public class ZButton : Button
{
private string UIB = "I";
public int _id_ { get; set; }
public int rowIndex { get; set; }
protected override void OnClick(EventArgs e)
{
Form frmNew = new Form(UIB);
frmNew.ShowDialog();
base.OnClick(e);
}
}
的我在窗体上放置该按钮,这里是在形式按钮的代码。
private void zButton1_Click(object sender, EventArgs e)
{
rowIndex = dataGridView1.CurrentRow.Index;
_id_ = Convert.ToInt16(dataGridView1["id_city", rowIndex].Value.ToString());
}
我不能访问这些属性(rowIndex位置)和(ID)和编译器会发出错误
The name 'rowIndex' does not exist in the current context
我是相当新的C#,所以我必须失去了一些东西obviuos。
完全不好的设计,定制控件显示表对话框取代
... –
'sender'是为其调用单击事件处理程序的按钮的实例。然而它是'object',所以你必须施放:'((ZButton)sender).rowIndex = ...'。在winforms中,每个控件都有名称,所以'zButton1.rowIndex = ...'也可以。 – Sinatr