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 5 years ago - PascalTalk #5: UX: Research, Design and Engineer
by LuriDarmawan in Tutorial & Community Project more 5 years ago - PascalTalk #4: Obrolan Ringan Seputar IT
by LuriDarmawan in Tutorial & Community Project more 5 years ago - PascalTalk #2: Membuat Sendiri SMART HOME
by LuriDarmawan in Tutorial & Community Project more 5 years ago - PascalTalk #3: RADically Fast and Easy Mobile Apps Development with Delphi
by LuriDarmawan in Tutorial & Community Project more 5 years ago - PascalTalk #1: Pemanfaatan Artificial Intelligence di Masa Covid-19
by LuriDarmawan in Tutorial & Community Project more 5 years ago - Tempat Latihan Posting
by LuriDarmawan in OOT more 6 years ago - Archive
- Looping lagi...
by idhiel in Hal umum tentang Pascal Indonesia more 13 years ago - [ask] koneksi ke ODBC user Dsn saat runtime dengan ado
by halimanh in FireBird more 13 years ago - Validasi menggunakan data tanggal
by mas_kofa in Hal umum tentang Pascal Indonesia more 13 years ago
Random Topic
- Nama Form CLX ilang dari taskbar
by opera in Tip n Trik Pemrograman more 18 years ago - Tanya untuk buat titik di ribuan
by lumpurpanas in Hal umum tentang Pascal Indonesia more 19 years ago - componen menampilkan *.doc atau *.Pdf
by hafiezd in Tip n Trik Pemrograman more 17 years ago - split string in delphi
by mbahdien in Form Enhancement & Graphical Controls more 18 years ago - Desain Kaos Delphi-ID
by kaka-delphi in Kritik & Saran more 19 years ago - gimana cara nampilin angka nol didepan
by putukaca in onLinux more 19 years ago - Mohon Solidaritasnya Untuk Sesama Programmer Delphi
by MrMixer in Kritik & Saran more 18 years ago - Tambah Data Ke String Grid Ni ?!
by jajang in Hal umum tentang Pascal Indonesia more 17 years ago - Edit pada kolom tertentu saja pada DBGrid
by a_mrecoba in Tip n Trik Pemrograman more 16 years ago - Ask: About mySQL tools ?
by cyber_hecker in MySQL more 20 years ago