//绑定菜单 private void BindMenu(DataTable dt) { foreach (DataRow row in dt.Rows) { ToolStripItem item = new ToolStripMenuItem(); item.Name = row[0].ToString(); item.Text = row[1].ToString(); item.Click += new EventHandler(contextMenuStrip1_ItemClick); contextMenuStrip1.Items.Add(item); //contextMenuStrip1.Items.Add(row[1].ToString(), null, contextMenuStrip1_ItemClick); } }
private void contextMenuStrip1_ItemClick(object sender, EventArgs e) { ToolStripItem item = (ToolStripItem)sender; MessageBox.Show(item.Name); }
|