private void treeView1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
TreeNode tn = treeView1.GetNodeAt(e.X, e.Y);
if (tn != null)
treeView1.SelectedNode = tn;
if (tn != null)
{
ContextMenu con = new ContextMenu();
MenuItem menu1 = new MenuItem("添加");
menu1.Click += new EventHandler(menu1_Click);
con.MenuItems.Add(menu1);
MenuItem menu2 = new MenuItem("修改");
menu2.Click += new EventHandler(menu2_Click);
con.MenuItems.Add(menu2);
MenuItem menu3 = new MenuItem("删除");
menu3.Click += new EventHandler(menu3_Click);
con.MenuItems.Add(menu3);
treeView1.ContextMenu = con;
con.Show(treeView1, new Point(e.X + 10, e.Y));
//this.contextMenuStrip1.Show(treeView1, new Point(e.X + 10, e.Y));
treeView1.ContextMenu = null;
}
}
}
{
if (e.Button == MouseButtons.Right)
{
TreeNode tn = treeView1.GetNodeAt(e.X, e.Y);
if (tn != null)
treeView1.SelectedNode = tn;
if (tn != null)
{
ContextMenu con = new ContextMenu();
MenuItem menu1 = new MenuItem("添加");
menu1.Click += new EventHandler(menu1_Click);
con.MenuItems.Add(menu1);
MenuItem menu2 = new MenuItem("修改");
menu2.Click += new EventHandler(menu2_Click);
con.MenuItems.Add(menu2);
MenuItem menu3 = new MenuItem("删除");
menu3.Click += new EventHandler(menu3_Click);
con.MenuItems.Add(menu3);
treeView1.ContextMenu = con;
con.Show(treeView1, new Point(e.X + 10, e.Y));
//this.contextMenuStrip1.Show(treeView1, new Point(e.X + 10, e.Y));
treeView1.ContextMenu = null;
}
}
}
以下是添些点击事件
private void menu1_Click(object sender, EventArgs e)
{
TreeNode tn = treeView1.SelectedNode;
String questionnaireTypeId = tn.Tag.ToString();
this.txtPQuestionnaireId.Text = tn.Tag.ToString();
}
private void menu2_Click(object sender, EventArgs e)
{
TreeNode tn = treeView1.SelectedNode;
String questionnaireTypeId = tn.Tag.ToString();
QuestionnaireWCF.QuestionnaireWCFClient client = new QuestionnaireWCF.QuestionnaireWCFClient();
QuestionnaireWCF.QQUESTIONNAIRETYPE questionnaireType = client.GetQQuestionnaireTypeById(questionnaireTypeId);
if (questionnaireType == null)
{
MessageBox.Show("未获取到数据");
return;
}
SetText(questionnaireType);
}
private void menu3_Click(object sender, EventArgs e)
{
TreeNode tn = treeView1.SelectedNode;
String questionnaireTypeId = tn.Tag.ToString();
QuestionnaireWCF.QuestionnaireWCFClient client = new QuestionnaireWCF.QuestionnaireWCFClient();
QuestionnaireWCF.QQUESTIONNAIRETYPE questionnaireType = client.GetQQuestionnaireTypeById(questionnaireTypeId);
client.DelQQuestionnaireType(questionnaireType);
BandingTreeView();
}
{
TreeNode tn = treeView1.SelectedNode;
String questionnaireTypeId = tn.Tag.ToString();
this.txtPQuestionnaireId.Text = tn.Tag.ToString();
}
private void menu2_Click(object sender, EventArgs e)
{
TreeNode tn = treeView1.SelectedNode;
String questionnaireTypeId = tn.Tag.ToString();
QuestionnaireWCF.QuestionnaireWCFClient client = new QuestionnaireWCF.QuestionnaireWCFClient();
QuestionnaireWCF.QQUESTIONNAIRETYPE questionnaireType = client.GetQQuestionnaireTypeById(questionnaireTypeId);
if (questionnaireType == null)
{
MessageBox.Show("未获取到数据");
return;
}
SetText(questionnaireType);
}
private void menu3_Click(object sender, EventArgs e)
{
TreeNode tn = treeView1.SelectedNode;
String questionnaireTypeId = tn.Tag.ToString();
QuestionnaireWCF.QuestionnaireWCFClient client = new QuestionnaireWCF.QuestionnaireWCFClient();
QuestionnaireWCF.QQUESTIONNAIRETYPE questionnaireType = client.GetQQuestionnaireTypeById(questionnaireTypeId);
client.DelQQuestionnaireType(questionnaireType);
BandingTreeView();
}