我有一個子類的按鈕與一對夫婦性質對象傾斜訪問類的屬性
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