2012-06-06 2 views
1

아주 간단한 질문을 선택했지만 나는 그것의 그것이 생각보다 더 힘들어 증명하려고 생각목록보기 하이라이트는

내가 초점이 목록보기 나뭇잎 경우에,이리스트 뷰 항목의 선택을 유지하고 싶습니다

잠시 후 hideselection 속성을 false로 설정 했으므로 문제가되지 않습니다. 목록보기가 포커스를 잃은 후 매우 밝은 회색 선택을 유지하게되므로 내 질문에 어떻게 항목을 선택했는지 제대로 표시 할 수 있습니다. 사용자는 행 텍스트 색이나 배경색을 변경하는 것과 같은 것을 인식 할 것입니까? 또는 전체 행이 처음 파란색으로 선택되었을 때 강조 표시를 유지 하시겠습니까?

나는 intelisense를 통해보고 있었는데 행이나 항목 또는 선택한 항목의 개별 색상 속성에 대해 아무것도 찾을 수없는 것 같습니까?

선택한 항목은 고유 한 배경색을 가지고 있기 때문에 존재해야합니다. 어디에서 변경할 수 있습니까?

아, 그리고 목록보기 내가 수도

감사에게

+0

가능한 [다른 컨트롤에 포커스가있을 때도 listview 선택한 행의 배경색을 변경하는 방법?] (http : // stackoverflow.co.kr/questions/5179664/how-to-change-listview-selected-row-backcolor-even-when-focus-on-another-control) –

+0

그래, 내가 사이트에 아직 접속하지 않아서 mods에 질문을했습니다. 무엇을해야할지 확신하지 못합니다. – Alex

+0

너무 광범위하므로 적절한 기술 (예 : winforms, wpf 등)을 사용하여 태그를 지정해야합니다. – Sinatr

답변

0

가능한 솔루션을 인터넷 검색을하는 동안 발견 할 수 있었던 유일한 방법을 사용할 수 없습니다 의미, 세부 사항보기를 유지하기 위해 필요합니까 다른 질문이 답이 될 :

How to change listview selected row backcolor even when focus on another control?

+0

정답을 잘못 제시 한 것 같지만 네가 정확히 찾고자하던 부분입니다! – Alex

+0

그 대답은 다루지 않지만 좋은 출발점이되어야하는 몇 가지 사항이 있습니다. – Alex

4

여기에 이미지 (예를 들어 체크 박스)이없는 복수 선택 및 을 허용하지 않는 ListView를위한 솔루션입니다. (이 listView1이라는 것이 예에서) ListView에 대한

  1. 설정 이벤트 핸들러 :
    • DrawItem
    • 휴가 (ListView에의 초점이 손실 될 때 호출)
  2. 가 선언 전역 int 변수 (즉, ListView를 포함하는 Form의 멤버 인이 예제에서 은 입니다. gListView1LostFocusItem) 값 -1을 할당하십시오.
    • int gListView1LostFocusItem = -1; 다음과 같이
  3. 이벤트 핸들러를 구현 :

    private void listView1_Leave(object sender, EventArgs e) 
    { 
        // Set the global int variable (gListView1LostFocusItem) to 
        // the index of the selected item that just lost focus 
        gListView1LostFocusItem = listView1.FocusedItem.Index; 
    } 
    
    private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e) 
    { 
        // If this item is the selected item 
        if (e.Item.Selected) 
        { 
         // If the selected item just lost the focus 
         if (gListView1LostFocusItem == e.Item.Index) 
         { 
          // Set the colors to whatever you want (I would suggest 
          // something less intense than the colors used for the 
          // selected item when it has focus) 
          e.Item.ForeColor = Color.Black; 
          e.Item.BackColor = Color.LightBlue; 
    
          // Indicate that this action does not need to be performed 
          // again (until the next time the selected item loses focus) 
          gListView1LostFocusItem = -1; 
         } 
         else if (listView1.Focused) // If the selected item has focus 
         { 
          // Set the colors to the normal colors for a selected item 
          e.Item.ForeColor = SystemColors.HighlightText; 
          e.Item.BackColor = SystemColors.Highlight; 
         } 
        } 
        else 
        { 
         // Set the normal colors for items that are not selected 
         e.Item.ForeColor = listView1.ForeColor; 
         e.Item.BackColor = listView1.BackColor; 
        } 
    
        e.DrawBackground(); 
        e.DrawText(); 
    } 
    

참고 :이 솔루션은 약간의 깜박임 현상이 발생할 수 있습니다. 이 문제를 해결하려면 ListView 컨트롤을 서브 클래스 화하여 보호 된 속성 DoubleBuffered을 true로 변경할 수 있습니다.

public class ListViewEx : ListView 
{ 
    public ListViewEx() : base() 
    { 
     this.DoubleBuffered = true; 
    } 
} 

도구 상자에 추가 할 수 있도록 위 클래스의 클래스 라이브러리를 만들었습니다.