/// <summary>返回按钮被单击 /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Back_button_Click(object sender, EventArgs e) { if (ShortcutKey_otTreeView.SelectedNode.Name == "BaseNode") { return; } string StrID = ShortcutKey_otTreeView.SelectedNode.Name; ShortcutKey_otTreeView.SelectedNode = ShortcutKey_otTreeView.SelectedNode.Parent; CurrentNode_dataGridView.SetSelectedRowByValue("ShortCutKeyID", StrID);//设置当前选中项目 }
/// <summary> 刷新DataGridView /// /// </summary> private void RefreshDataGridView() { string CurrentSelectID = CurrentNode_dataGridView.GetSelectedRowValue("ShortCutKeyID"); TreeNode CurrentNode = ShortcutKey_otTreeView.SelectedNode; List <tShortCutKey> tShortCutKeyListTemp = new List <tShortCutKey>(); if (CurrentNode == null || CurrentNode.Name == "BaseNode") { tShortCutKeyListTemp = tShortCutKeyDataSource.Where(T1 => string.IsNullOrEmpty(T1.ParentID)).ToList(); } else { tShortCutKeyListTemp = tShortCutKeyDataSource.Where(T1 => CurrentNode.Name == T1.ParentID).ToList(); } List <vShortCutKey> vShortCutKeyListTemp = new List <vShortCutKey>();//最终的数据源 foreach (tShortCutKey tShortCutKeyItem in tShortCutKeyListTemp) { vShortCutKey vShortCutKeyTemp = UniversalMethod.ClassToClass <tShortCutKey, vShortCutKey>(tShortCutKeyItem, new vShortCutKey()); vShortCutKeyTemp.Icon = tShortCutKeyItem.ShortCutKeyImg.ToImage(); vShortCutKeyTemp.TargetIcon = tShortCutKeyItem.TargetProgramImg.ToImage(); vShortCutKeyTemp.KeyName = UniversalMethod.GetKeyName(tShortCutKeyItem.ShortCutKey); vShortCutKeyTemp.ShortCutKeyTypeName = UniversalMethod.GetTypeName(tShortCutKeyItem.ShortCutKeyType); vShortCutKeyTemp.OwningChidrenNode = OwningChidren(vShortCutKeyTemp); vShortCutKeyListTemp.Add(vShortCutKeyTemp); } CurrentNode_dataGridView.DataSource = vShortCutKeyListTemp; #region 子节点的话就用颜色区分出来 foreach (DataGridViewRow Rowitem in CurrentNode_dataGridView.Rows) { if (Rowitem.Cells["IsChidren"].Value.ToString() == "True") { DataGridViewCellStyle CellStyleTemp = Rowitem.DefaultCellStyle; CellStyleTemp.BackColor = Color.Blue; //CellStyleTemp.SelectionBackColor = ShortcutKeyItem_Box.ShortcutKeyItem_Box_StateColor.OwiningChidren.Click; } } #endregion 子节点的话就用颜色区分出来 CurrentNode_dataGridView.SetSelectedRowByValue("ShortCutKeyID", CurrentSelectID); }
/// <summary>删除按钮被单击 /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteCurrentNode_button_Click(object sender, EventArgs e) { String StrID = CurrentNode_dataGridView.GetSelectedRowValue("ShortCutKeyID"); if (string.IsNullOrEmpty(StrID)) { return; } int IntSelectedRow = CurrentNode_dataGridView.SelectedRows[0].Index; tShortCutKey RemoveData = new tShortCutKey() { ShortCutKeyID = StrID }; if (new ShortcutKeyManageService().DeleteShortCutKey(RemoveData)) { InitKeyList(); } CurrentNode_dataGridView.SetSelecetedRowByRowIndex(IntSelectedRow); }
/// <summary> 添加按钮被单击 /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddCurrentNode_button_Click(object sender, EventArgs e) { string NewId = AddtShortcutKey(true); CurrentNode_dataGridView.SetSelectedRowByValue("ShortCutKeyID", NewId);//选中刚添加的那一行 }