/// <summary> /// Delete Grid. /// </summary> private void DeleteBtn_Click(object sender, EventArgs e) { try { var node = GridTreeView.SelectedNode; if (node == null) { MessageBox.Show("请选择需要删除的网格", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var tag = (IDValuePair <Int32, String>)node.Tag; if (MessageBox.Show(String.Format("\"{0}\"将被删除,您确定要删除吗?", tag.Value), "确认对话框", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK) { new Grid().DeleteGrids(new List <IDValuePair <Int32, String> >() { tag }); GridTreeView.Nodes.RemoveByKey(tag.ID.ToString()); GridTreeView.Focus(); DeleteBtn.Enabled = EditBtn.Enabled = GridTreeView.Nodes.Count > 0 && GridTreeView.SelectedNode != null; Common.WriteLog(DateTime.Now, EnmMsgType.Info, Common.CurUser.UserName, "Delta.MPS.AccessSystem.GridManagerForm.DeleteBtn.Click", String.Format("删除网格:[{0} - {1}]", tag.ID, tag.Value), null); } } catch (Exception err) { Common.WriteLog(DateTime.Now, EnmMsgType.Error, "System", "Delta.MPS.AccessSystem.GridManagerForm.DeleteBtn.Click", err.Message, err.StackTrace); MessageBox.Show(err.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Select TreeView Node By Node ID. /// </summary> /// <param name="nodeId">node id</param> private void SelectTreeNodeByID(Int32 nodeId) { var nodes = GridTreeView.Nodes.Find(nodeId.ToString(), false); if (nodes != null && nodes.Length > 0) { GridTreeView.SelectedNode = nodes[0]; GridTreeView.Focus(); } }
/// <summary> /// Select TreeView Node By Node Text. /// </summary> /// <param name="text">node text</param> private void SelectTreeNodeByText(String text) { foreach (TreeNode tn in GridTreeView.Nodes) { if (tn.Text.Equals(text)) { GridTreeView.SelectedNode = tn; GridTreeView.Focus(); break; } } }