Home > GridView > Tao MenuStrip khi nhan chuot phai vao GridView

Tao MenuStrip khi nhan chuot phai vao GridView

November 12, 2012 Leave a comment Go to comments

public FrmInsert()
{
InitializeComponent();
InitMenuStripGridView();
}

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:
dataGridView1.ContextMenuStrip.Items.Add(deleteToolStripMenuItem);
dataGridView1.ContextMenuStrip.Items.Add(reloadToolStripMenuItem);
}

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)
{
MessageBox.Show(“Delete_1”);
}
void subMenu2_Click(object sender, EventArgs e)
{
MessageBox.Show(“Delete_2”);
}

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: