C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[71498] Re:ListBox에 특정 Item이 선택이 안되록 하는 방법 좀 알려주세여
빌더초보 [] 3072 읽음    2014-06-28 13:58
비슷한 질문이 올라온 적이 있네요.

"아이템이 선택이 되지 않도록" 은 못하는것 같고,
"아이템이 선택이 되지 않은 것 처럼" 보이게 하는 방법입니다.

ListBox의 Style 속성을 lbOwnerDrawFixed 나 lbOwnerDrawVariable 로 변경한 후,
OnDrawItem 이벤트를 아래와 같이 하세요.

//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int Index, TRect &Rect,
		  TOwnerDrawState State)
{

	TListBox *AListBox=(TListBox*)Control;
	// eliminate artifacts
	AListBox->Canvas->Pen->Color=AListBox->Color;
	AListBox->Canvas->FillRect(Rect);

	// check to see if Index is our "disabled" item
	if (ListBox1_ItemEnabled[Index] == false)
	{

		// gray out it's text
		AListBox->Canvas->Font->Color = clGray;

		// white out the selection rectangle
		if (State.Contains(odSelected))
		{
			AListBox->Canvas->Brush->Color = AListBox->Color;
			AListBox->Canvas->FillRect(Rect);
		}

	}
	else AListBox->Canvas->Font->Color = clBlack;

	AListBox->Canvas->TextOut(Rect.Left, Rect.Top, AListBox->Items->Strings[Index]);

}
//---------------------------------------------------------------------------


여기서 ListBox1_ItemEnabled 는 bool 형 vector로,
ListBox1과 따라다니면서 Item 이 변할 때마다 같이 변경 해야 됩니다.



출처 : http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_qna&no=71419







초심자3 님이 쓰신 글 :
: ListBox에 20개 정도의 item들이 있다면 이중에서 2번째 item이선택이 되지 않도록 하고 싶습니다.
:
: 이게 가능할까요? 방법을 아신느 분은 알려주세요...
:
: (삭제가 아닌 항목은 그대로이지만 선택만 안되게 하는 것입니다.)

+ -

관련 글 리스트
71490 ListBox에 특정 Item이 선택이 안되록 하는 방법 좀 알려주세여 초심자3 2989 2014/06/27
71498     Re:ListBox에 특정 Item이 선택이 안되록 하는 방법 좀 알려주세여 빌더초보 3072 2014/06/28
71501         Re:Re:ListBox에 특정 Item이 선택이 안되록 하는 방법 좀 알려주세여 초심자3 3143 2014/06/30
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.