| mege | 15.04.2004 - 15:45:40 |
| http://www.swissdelphicenter.ch/torry/showcode.php?id=737
[img:83bb7570b6]http://www.swissdelphicenter.ch/screenshots/tip737.png[/img:83bb7570b6] 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 :83bb7570b6 ComboBox1'in DrawItem Eventına 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. 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; | |