/// <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="Parent">父节点ID,为空则为根节点</param> private void ShowKey(string ParentID = null) { List <tShortCutKey> tShortCutKeyTempList = null; if (string.IsNullOrEmpty(ParentID)) { tShortCutKeyTempList = tShortCutKeyDataSource.Where(T1 => string.IsNullOrEmpty(T1.ParentID)).ToList(); } else { tShortCutKeyTempList = tShortCutKeyDataSource.Where(T1 => T1.ParentID == ParentID).ToList(); } //将tShortCutKey转换成vShortCutKey CurrentNodetShortCutKey = tShortCutKeyTempList.Select(T1 => UniversalMethod.ClassToClass <tShortCutKey, vShortCutKey>(T1, new vShortCutKey())).ToList(); CurrentNodetShortCutKey.ForEach(T1 => T1.OwningChidrenNode = OwningChidren(T1));//加入是否有下级节点 //keyLayoutShow.DataSource = CurrentNodetShortCutKey; }