본문 바로가기

IT/Winform & Devexpress

TreeList 선택된 노드 설정(FocusedNode Setting) - Find, Set, Next, Prev, Color, Level



Devexpress TreeList FocusedNode에 대한 포스팅


TreeList는 일종의 조직도를 손쉽게 표현 해주는 컨트롤 입니다.


이포스트는 TreeList를 전부 구성한 후 FocusedNode 즉 선택된 노드의 배경색, 그리고 Action등을 처리하는 방법에 대해서 알아보도록 하겠습니다.


1. FocusedNode 배경색 변경에 대해 설명해 드리겠습니다.

선택된 노드의 배경색과 폰트를 조절 하고 싶은 경우가 있습니다.

디자이너를 이용하는 경우 TreeList를 선택하고 속성에서 조작하면 됩니다. 속성 -> Appearance -> FocusedRow -> BackColr설정

주의해야 될 것은 EnableAppearanceFocusedCell의 상태를 잘 확인해 봐야 합니다.
아래 devexpress측의 설명을 첨부합니다.
Expanded Syntax

Property value

Type: Boolean 
true if the appearance settings for the focused cell are enabled; otherwise, false
The default is true.

Expanded Remarks

The EnableAppearanceFocusedCell property specifies whether the appearance settings specified by the TreeListAppearanceCollection.FocusedCell property are in effect.

If the focused cell is a custom painted cell or its appearance settings are specified in the TreeList.NodeCellStyle event handler the settings provided by the TreeListAppearanceCollection.FocusedCell property are ignored regardless of the EnableAppearanceFocusedCell property's value.


2. FocusedNode 수동 설정 - 마우스 클릭이 아닌 임의 선택이 필요 할 때의 방법을 소개해드리겠습니다.

임의로 FocusedNode를 변경하고 싶은 경우가 있으실거에요. 마우스클릭 외에 다른 로그를통해 해당 위치를 찾아가게끔 하고싶은 경우이지요.

treelist1.FocusedNode = 원하는 노드의 형태로 사용하시면 됩니다.

TreeList의 노드 타입으로 원하는 노드를 찾아 대입해주면 자동으로 FocusedNode로 변경됩니다.

※ 원하는 노드는 자유롭게 찾으시면 되나 저는 FindNodeByFieldValue를 자주 사용합니다.

treelist1.FocusedNode = treelist1.FindNodeByFieldValue("Name", "찾고싶다");


3. FocusedNode를 기준으로 전/후 노드를 선택하고 싶을 때의 방법을 소개해드리겠습니다.

현재 선택된 노드의 전/후 노드를 선택하고 싶은 경우가 있을 겁니다. 예를들어서 화살표 아이콘을 통해 다음 노드를 바로 검색 할 수 있도록 하는 부분이지요

treelist1.FocusedNode = treelist1.FocusedNode.NextNode;

treelist1.FocusedNode = treelist1.FocusedNode.PrevNode;

4. FocusedNode의 레벨에 따른 액션을 다르게 하고싶을 때의 방법을 소개해드리겠습니다.
treelist1.FocusedNode.Level 옵션을 사용하시면 됩니다.
조직도로 예를들어 보겠습니다. level 1은 회사, level 2는 부서, level3은 사원이라고 가정해 보겠습니다. 해당 노드를 더블클릭 하였을때 액션이 각각 부서목록 출력, 부서원 목록 출럭, 사원 정보 출력 이라면 아래와 같은 코드가 필요합니다.
private void treelist1_DoubleClick(object sender, EventArgs e) 
 { 
if (treelist1.FocusedNode.Level == 1) { 부서목록 팝업 출력 } 
else if(treelist2.FocusedNode.Level == 2) { 부서원 목록 팝업 출력 } 
else if(treelist2.FocusedNode.Level == 3) { 사원 정보 팝업 출력 } 
}



반응형