Çok sütunlu ComboBox

Yazdığınız makaleleri ve üyelerimizin işine yarayacağını düşündüğünüz kodlarınızı gönderebilirsiniz. Bu foruma soru sormayın!
Cevapla
Kullanıcı avatarı
mege
Admin
Mesajlar: 2360
Kayıt: 05 Şub 2004 04:32
Konum: Beşiktaş
İletişim:

Çok sütunlu ComboBox

Mesaj gönderen mege »

http://www.swissdelphicenter.ch/torry/s ... php?id=737
Resim

yukarıdaki şekilde çok sütunllu combobox için bi kod parçası.
alttaki kodda ben birkaç değişiklik yapıp her satır ve sütunun rengini değiştirdim. gerekirse değişiklik yapabilirsiniz.

İyi çalışmalar

Combobox un Style özelliği csOwnerDrawFixed yapılacak.


ComboBox1'in DrawItem Eventına

Kod: Tümünü seç

procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
  strVal, strAll: string;
  pos1, pos2: Integer;
  rc: TRect;
  arrWidth: array [0..3] of Integer;
  arrColor: array [0..7] of TColor;
begin
  arrColor[0]:= clAqua;
  arrColor[1]:= clBlack;
  arrColor[2]:= clBlue;
  arrColor[3]:= clDkgray;
  arrColor[4]:= clfuchsia;
  arrColor[5]:= clgreen;
  arrColor[6]:= cllime;
  arrColor[7]:= clolive;

  Combobox1.Canvas.Brush.Style := bsSolid;
  Combobox1.Canvas.FillRect(Rect);
  strAll := Combobox1.Items[Index];

  arrWidth[0] := 0;
  arrWidth[1] := 100;  // Width of column 1
  arrWidth[2] := 200;  // Width of column 2
  arrWidth[3] := 300;  // Width of colimn 3

  rc.Left   := Rect.Left + arrWidth[0] + 2;
  rc.Right  := Rect.Left + arrWidth[1] - 2;
  rc.Top    := Rect.Top;
  rc.Bottom := Rect.Bottom;

  pos1   := Pos(';', strAll);
  strVal := Copy(strAll, 1, pos1 - 1);
  Combobox1.Canvas.Brush.Color := arrColor[index];
  Combobox1.Canvas.TextRect(rc, rc.Left, rc.Top, strVal);
  Combobox1.Canvas.MoveTo(rc.Right, rc.Top);
  Combobox1.Canvas.LineTo(rc.Right, rc.Bottom);


  rc.Left  := Rect.Left + arrWidth[1] + 2;
  rc.Right := Rect.Left + arrWidth[2] - 2;
  strAll := Copy(strAll, pos1 + 1, Length(strAll) - pos1);
  pos1   := Pos(';', strAll);
  strVal := Copy(strAll, 1, pos1 - 1);

  Combobox1.Canvas.Brush.Color := arrColor[index+1];
  Combobox1.Canvas.TextRect(rc, rc.Left, rc.Top, strVal);
  Combobox1.Canvas.MoveTo(rc.Right, rc.Top);
  Combobox1.Canvas.LineTo(rc.Right, rc.Bottom);

  rc.Left  := Rect.Left + arrWidth[2] + 2;
  rc.Right := Rect.Left + arrWidth[3] - 2;
  strAll := Copy(strAll, pos1 + 1, Length(strAll) - pos1);
  pos1   := Pos(';', strAll);
  strVal := Copy(strAll, 1, pos1 - 1);
  Combobox1.Canvas.Brush.Color := arrColor[index+3];
  Combobox1.Canvas.TextRect(rc, rc.Left, rc.Top, strVal);
  Combobox1.Canvas.MoveTo(rc.Right, rc.Top);
  Combobox1.Canvas.LineTo(rc.Right, rc.Bottom);
  strAll := Copy(strAll, pos1 + 1, Length(strAll) - pos1);
end;
Forma ayrıca bir buton ekleyip kayıt ekleyin.

Kod: Tümünü seç

procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
for i:=1 to 10 do
  with Combobox1.Items do
  begin
    Add(inttostr(i)+'.Satır;second;third;');
  end;
end;
Cevapla