Arsip: CheckListBox ?

more 19 years ago
umarbakri
Apakah checklistbox bisa dibuat menjadi (2 , 3 atau beberapa) colom tanpa menghilangkan kotak checklist-nya.
(tampilannya mirip seperti valuelisteditor/dbgrid)
aku udah coba merubah properti colum-nya namun tak ada pengaruhnya.
trim's

more 19 years ago
ZeAL
ahhh... jadi pengennya muncul disebelahnya kan? gak mau ada scroll nya?
rubah properties Column jadi 2 (atau lebih, tergantung keinginan)..
dan dia gak akan berubah bentuknya kalo ukuran checklistboxnya masih lebih besar dibanding banyak checklistnya.. (ngerti kan yah maksud gue?)

more 19 years ago
umarbakri
maksud aku :
bisa ngak nampilkan field seperti didbgrid :
gambaranya seperti ini :
tandachecklist | field1 | field2
tandakotak | Baju | 10000

more 19 years ago
ZeAL
oww.. kalo gitu pertanyaannya salah.... seharusnya: "bisa gak dbgrid dikasih checkbox?"
Kalo gitu sih..hmm.. lebih gampang pake custom component.. gak usah repot gituh...
cari aja di torry.net.. banyak banget tuh..

more 19 years ago
ZeAL
atau bisa pake kode ini...
tapi ini blon pernah gue test dan ini cuma gue copy-paste ajah dari codebank gue...
Two procedures follow. The first is called from the OnDrawColumnCell event of any grid that has visible boolean fields, as so:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
DrawCheckBoxes(Sender, Rect, DataCol, Column, State);
end;
Here's the procedure. Place this in your toolkit or utility unit.
procedure DrawCheckBoxes(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
MyRect: TRect;
fld: TField;
begin
with (Sender as TDBGrid) do
begin
fld := Column.Field;
if fld is TBooleanField then
begin
MyRect.Top := ((Rect.Bottom - Rect.Top - 11) div 2) + Rect.Top;
MyRect.Left := ((Rect.Right - Rect.Left - 11) div 2) + Rect.Left;
MyRect.Bottom := MyRect.Top + 10;
MyRect.Right := MyRect.Left + 10;
if gdSelected in State then
Canvas.Pen.Color := clWhite
else
Canvas.Pen.Color := clBlack;
Canvas.Polyline([
Point(MyRect.Left, MyRect.Top), Point(MyRect.Right, MyRect.Top),
Point(MyRect.Right, MyRect.Bottom), Point(MyRect.Left, MyRect.Bottom),
Point(MyRect.Left, MyRect.Top)]);
if fld.AsBoolean then
begin
Canvas.MoveTo(MyRect.Left + 2, MyRect.Top + 4);
Canvas.LineTo(MyRect.Left + 2, MyRect.Top + 7);
Canvas.MoveTo(MyRect.Left + 3, MyRect.Top + 5);
Canvas.LineTo(MyRect.Left + 3, MyRect.Top + 8);
Canvas.MoveTo(MyRect.Left + 4, MyRect.Top + 6);
Canvas.LineTo(MyRect.Left + 4, MyRect.Top + 9);
Canvas.MoveTo(MyRect.Left + 5, MyRect.Top + 5);
Canvas.LineTo(MyRect.Left + 5, MyRect.Top + 8);
Canvas.MoveTo(MyRect.Left + 6, MyRect.Top + 4);
Canvas.LineTo(MyRect.Left + 6, MyRect.Top + 7);
Canvas.MoveTo(MyRect.Left + 7, MyRect.Top + 3);
Canvas.LineTo(MyRect.Left + 7, MyRect.Top + 6);
Canvas.MoveTo(MyRect.Left + 8, MyRect.Top + 2);
Canvas.LineTo(MyRect.Left + 8, MyRect.Top + 5);
end;
end;
end;
end;
There's a little setup involved. Select each visible boolean field in the fields editor and set the DisplayValues to ' ;'. That's space + semicolon. I like the DisplayWidth set to 2.
The next procedure is optional/ extra. It's a keystroke handler that will change the value of the field if the user presses space, T, F, Y, or N.Place it in your utility unit also and call it from your OnKeyPress event in the grid as so:
procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
CheckBoxKeyPress(Sender, Key);
end;
And here's the procedure:
procedure CheckBoxKeyPress(const Sender: TObject; var Key: Char);
var
fld: TField;
tbl: TDataset;
i: integer;
begin
if UpCase(Key) in [' ', 'T', 'F', 'Y', 'N'] then
begin
with (Sender as TDBGrid) do
begin
i := SelectedIndex;
fld := SelectedField;
tbl := fld.DataSet;
if fld is TBooleanField then
begin
if not (tbl.State in [dsEdit, dsInsert]) then
tbl.Edit;
if Key = ' ' then
fld.AsBoolean := not fld.AsBoolean
else
if (UpCase(Key) = 'T') or (UpCase(Key) = 'Y') then
fld.AsBoolean := True
else
fld.AsBoolean := False;
tbl.Post;
Key :=#0;
Inc(i);
if i = FieldCount then
begin
i := 0;
tbl.Next;
if tbl.EOF then
tbl.Append;
end;
SelectedIndex := i;
end;
end;
end;
end;
more ...
- Pages:
- 1
reply |
Report Obsolete
AI Forward

🚀 We're thrilled to partner with Alibaba Cloud for "AI Forward - Alibaba Cloud Global Developer Summit 2025" in Jakarta! Join us and explore the future of AI. Register now:
https://int.alibabacloud.com/m/1000400772/
#AlibabaCloud #DeveloperSummit #Jakarta #AIFORWARD
Last Articles
Last Topic
- PascalTalk #6: (Podcast) Kuliah IT di luar negeri, susah gak sih?
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #5: UX: Research, Design and Engineer
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #4: Obrolan Ringan Seputar IT
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #2: Membuat Sendiri SMART HOME
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #3: RADically Fast and Easy Mobile Apps Development with Delphi
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #1: Pemanfaatan Artificial Intelligence di Masa Covid-19
by LuriDarmawan in Tutorial & Community Project more 4 years ago - Tempat Latihan Posting
by LuriDarmawan in OOT more 5 years ago - Archive
- Looping lagi...
by idhiel in Hal umum tentang Pascal Indonesia more 12 years ago - [ask] koneksi ke ODBC user Dsn saat runtime dengan ado
by halimanh in FireBird more 12 years ago - Validasi menggunakan data tanggal
by mas_kofa in Hal umum tentang Pascal Indonesia more 12 years ago
Random Topic
- gmn caranya nyalain LED lewat PC
by adhiet_cool7 in Enginering more 18 years ago - muncul error dgn komponen UNIDAC
by aandrie77 in Lain-lain more 13 years ago - Tipe data utk simpan data gambar
by onsir in Lain-lain more 16 years ago - Wait for file lock released
by danieljun in Tip n Trik Pemrograman more 17 years ago - Delphi XE
by LuriDarmawan in OOT more 14 years ago - Tanya TEdit ??
by gold3n_b0y in Hal umum tentang Pascal Indonesia more 19 years ago - Speed On TMediaPlayer
by clark in Multimedia & Graphic Enhancement more 18 years ago - Licence Delphi
by anaconda in MySQL more 17 years ago - Fuzzy logic menggunakan delphi
by akiffistek03 in Tutorial & Community Project more 17 years ago - Cara perhitungan pinjaman
by ichan29 in Tip n Trik Pemrograman more 17 years ago