Tao MenuStrip khi nhan chuot phai vao GridView

public FrmInsert()

void InitMenuStripGridView()
//Tao ra 1 menu strip cho GridView la “Delete”
dataGridView1.ContextMenuStrip = new ContextMenuStrip();

//Init deleteToolStripMenu for GridView
ToolStripMenuItem deleteToolStripMenuItem = new ToolStripMenuItem(“Delete”);

//Khi nhan vao menu nay, thi se thuc hien trong su kien nay:
deleteToolStripMenuItem.Click += new EventHandler(deleteToolStripMenutem_Click);

// Sub menu of “Delete” menu :
deleteToolStripMenuItem.DropDownItems.Add(“Delete_1”, null, subMenu1_Click);  //subMenu1_Click la su kien khi click vao Delete_1
deleteToolStripMenuItem.DropDownItems.Add(“Delete_2”, null, subMenu2_Click); //subMenu2_Click la su kien khi click vao Delete_2

//Init reloadToolStripMenu for GridView:
ToolStripMenuItem reloadToolStripMenuItem = new ToolStripMenuItem(“Reload”);

//Khi nhan vao menu nay, thi se thuc hien trong su kien nay:
reloadToolStripMenuItem.Click += new EventHandler(reloadToolStripMenuItem_Click);

//Add delete & reload menu into grid:

void deleteToolStripMenutem_Click(object sender, EventArgs e)
MessageBox.Show(“Clicked delete!”);
void reloadToolStripMenuItem_Click(object sender, EventArgs e)
MessageBox.Show(“Clicked reload!”);
void subMenu1_Click(object sender, EventArgs e)
void subMenu2_Click(object sender, EventArgs e)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s