我有我從下面編程創建CheckedListBox
控制...當我動態創建的項目如何在動態創建的winform控件上引發動態創建的事件?
Button btnSelectAll = new Button();
btnSelectAll.Text = "Select All";
btnSelectAll.Name = item.Id;
btnSelectAll.Tag = param.Id;
CheckedListBox chkListBox = new CheckedListBox();
chkListBox.Size = new System.Drawing.Size(flowPanel.Size.Width - lblListBox.Size.Width - 10, 100);
//set the name and tag for downstream event handling since two-way bindings are not possible with control
chkListBox.Tag = param.Id;
chkListBox.Name = item.Id;
chkListBox.ItemCheck += new ItemCheckEventHandler(chkListBox_ItemCheck);
btnSelectAll.Click += new EventHandler(btnSelectAll_Click);
注意,我還添加了一個事件處理程序,只要在chkListBox的ItemCheck被擊中。在代碼中的其他地方...我做...
CheckedListBox tmpCheckedListBox = cntrl as CheckedListBox;
for (int i = 0; i < tmpCheckedListBox.Items.Count; i++)
{
tmpCheckedListBox.SetItemChecked(i, true);
}
當我這樣做,它doens't提高ItemChecked事件。我該如何提高此事件,使其彷彿用戶點擊了該項目?
沒有,調用SetItemChecked()絕對引發ItemChecked事件。有些東西是看不見的。 – 2013-03-19 22:39:23