Jump to content
과거의 기술자료(읽기 전용): https://tech.devgear.co.kr ×
과거의 기술자료(읽기 전용): https://tech.devgear.co.kr

[TMS] TAdvStringGrid 기능소개 - ComboBox 항목에 연결된 데이터 추가하기.


Recommended Posts

( TAdvStringGrid  콤보박스 관련해서는 기고되어 있는 위 링크 게시글을 먼저 확인 하시기 바랍니다. 이곳에서 사용된 샘플코드에 추가하여 설명 합니다.)

 

image.png

ComboBox 사용시 화면에 표시되는 데이터 리스트와 함께 1:1 쌍으로 숨겨진 데이터를 저장 하는 방법입니다.

사용자가 컴보박스 항목을 선택하면 연결된 데이터를 사용 할 수 있습니다.

가령 제품명을 콤보박스에 뿌려주고 연결된 제품코드 데이터를 가져오게 할 수 있습니다.

샘플 소스에서는 AdvStringGrid1.Cells[ 2,7 ] 셀을 사용 합니다.

컴보박스에 데이터를 넣을때 AddComboString 대신 AddObject를 사용하여 기본 문자열 데이터와 함께 정수 데이터를 추가로 같이 넣어 줍니다.

델파이 내장 기본 콤보박스 및 TStringList 에서도 AddObject 이용하여 같은 똑같은 방법으로 사용 할 수 있습니다.

사용자가 콤보박스 항목 선택시 연결된 숨겨진 데이터를 가져 올때는 아래와 같이 TObject로 넣어진 항목을 Integer 로 캐스팅 하는 과정만 거치면 됩니다.

Integer( ComboBox.Items.Objects[ ComboBox.ItemIndex ] ) 

//****************************************************************************************************
procedure TMvForm.BT_SetComboBoxClick(Sender: TObject);
begin
  AdvStringGrid1.Cells[ 2,5 ] := SList[0];   // 특정 이벤트에서 ComboBox 초기값 지정
  AdvStringGrid1.Cells[ 2,7 ] := 'KOR';      // 특정 이벤트에서 ComboBox 초기값 지정
end;

procedure TMvForm.BT_GetComboBox5Click(Sender: TObject);
begin
  with AdvStringGrid1 do begin
    ShowMessage( ComboBox.Items.IndexOf( Cells[2,5] ).ToString  + ' : ' + Cells[ 2,5 ]   );
  end;
end;

procedure TMvForm.BT_GetComboBox7Click(Sender: TObject);
begin
  with AdvStringGrid1 do begin
       if ( Col = 2 ) and ( Row = 7 )then  // 현재 선택된 Cell 항목 ( Active Cell )
          ShowMessage( Integer( ComboBox.Items.Objects[ ComboBox.ItemIndex ] ).ToString );
  end;
end;

//****************************************************************************************************************
procedure TMvForm.AdvStringGrid1HasComboBox(Sender: TObject; ACol, ARow: Integer; var HasComboBox: Boolean);
begin
  if ( ( Acol = 2 ) and ( ARow  = 5 ) )  or   // 특정셀 콤보박스 항상 보이게.
     ( ( Acol = 2 ) and ( ARow  = 7 ) ) then
    HasComboBox := TRUE;
end;

procedure TMvForm.AdvStringGrid1GetEditorProp(Sender: TObject; ACol, ARow: Integer; AEditLink: TEditLink);
var
  i : integer;
begin
  with AdvStringGrid1 do begin
    if ( Acol = 2 ) and ( ARow  = 5 ) then
    begin
      ClearComboString;
      for i := 0 to SList.Count - 1 do
        AddComboString( SList[i]  );
    end

    else if ( Acol = 2 ) and ( ARow  = 7 ) then
    begin
      ClearComboString;
      ComboBox.Items.AddObject('KOR', TObject(1234) );
      ComboBox.Items.AddObject('USA', TObject(5678) );
      ComboBox.Items.AddObject('FRA', TObject(9101) );
      ComboBox.Items.AddObject('ENG', TObject(2025) );
    end;

  end;
end;

procedure TMvForm.AdvStringGrid1GetEditorType(Sender: TObject; ACol, ARow: Integer; var AEditor: TEditorType);
var
  sList : TStringList;
begin
  with AdvStringGrid1 do begin
    if ( ( Acol = 2 ) and ( ARow  = 5 ) )  or
       ( ( Acol = 2 ) and ( ARow  = 7 ) ) then
       aEditor := edComboList;
  end;
end;

 

데모영상

 

이 댓글 링크
다른 사이트에 공유하기

이 토의에 참여하세요

지금 바로 의견을 남길 수 있습니다. 그리고 나서 가입해도 됩니다. 이미 회원이라면, 지금 로그인하고 본인 계정으로 의견을 남기세요.

Guest
이 토픽(기고/질문)에 답하기

×   서식있는 텍스트로 붙여넣기.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   이전에 작성한 콘텐츠가 복원되었습니다..   편집창 비우기

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

중요한 정보

이용약관 개인정보보호정책 이용규칙 이 사이트가 더 잘 작동하기 위해 방문자의 컴퓨터에 쿠키가 배치됩니다. 쿠키 설정 변경에서 원하는 설정을 할 수 있습니다. 변경하지 않으면 쿠키를 허용하는 것으로 이해합니다.