Arsip: combo box tidak bisa melebar
more 17 years ago
flamade
bro bro delphiers semua
saya kan punya data di combo box (lebar combobox 10 karakter) yang isinya panjang2 misal lebih dari 50 karakter.
saat saya menekan combobox tersebut kok data yang panjangnya 50 karakter tadi terpotong (hanya ditampilkan sekitar 10 karakter sesuai lebar combobox di form)
bagaimana caranya agar dengan lebar combobox tetap 10 karakter, tetapi saat di dropdown, data yang 50karakter tadi tetap ditampilkan utuh.
mohon bantuannya
more 17 years ago
flamade
bukan begitu mas, maksudnya ukuran combobox-nya tetep sama tetapi tampilan isi-nya (saat di dropdown) ditampilkan semua teksnya
begitu... ngerti ga yang saya maksudkan ?
kalo yang mas kofa tunjukkan kan, setelah di klik comboboxnya, comboboxnya jadi melebar. bukan isinya.
more 17 years ago
mas_kofa
gak ngerti juga apa maksudmu....????
atau tinggal dilebarkan aja tu combo selebar 50 karakter saat design.........
begitu kah.....??????? atau set maxlength nya 50 atau nol
more 17 years ago
flamade
bener seperti itu
tapi ... properties DropDownWidth tidak ada / tidak dikenal buat ComboBox
yg ada juga DropDownCount, tapi meski sudah di ganti value nya dr 8 menjadi 50, tetap aja ke potong.
yg mas cyber hacker kok bisa ? emang dropdownwidth dikenal ??
more 17 years ago
zieborg
koreksi buat bung @CH:
yang ditanyakan adalah combobox, bukan dblookupcombo, combobox tidak punya property dropdownwidth. CMIIW
buat @flamade:
ada 2 alternatif, pake komponen3rd party, atau hack combobox standar.
untuk cara ke-2 saya nemu kodenya di arsip-arsip lamaku, caranya sbb:
buat satu unit : file->new->unit (atau satukan dengan unit yg sudah ada), tambahkan kode berikut ke unit tsb :
unit Unit2;
interface
uses
Windows, Messages, Classes, Controls, Forms, StdCtrls, Dialogs, Sysutils;
implementation
var
cwpHandle: THandle;
SaveRight:Integer;
procedure AutoSetComboxDropDownWidth( AComboBox: TComboBox );
var
i: Integer;
MaxWidth: Integer;
CurWidth: Integer;
TempSize: SIZE;
TempHDC: HDC;
SaveFont: HFont;
begin
MaxWidth := AComboBox.Width;
TempHDC := GetDC(0);
try
for i := 0 to AComboBox.Items.Count-1 do
begin
SaveFont := SelectObject( TempHDC, AComboBox.Font.Handle );
Windows.GetTextExtentPoint32( TempHDC, PChar(AComboBox.Items[i]),Length(AComboBox.Items[i]), TempSize );
SelectObject( TempHDC, SaveFont );
if AComboBox.Items.Count>AComboBox.DropDownCount then
CurWidth := TempSize.cx + (GetSystemMetrics(SM_CXVSCROLL)+8)
else
CurWidth := TempSize.cx+8;
if CurWidth>MaxWidth then
MaxWidth := CurWidth;
end;
finally
ReleaseDC(0, TempHDC );
end;
SaveRight := AComboBox.ClientOrigin.X + AComboBox.Width;
AComboBox.Perform( CB_SETDROPPEDWIDTH, MaxWidth, 0 );
end;
procedure MoveDropDownListIfNecessary( AComboBoxListHandle: LongInt );
var
R: TRect;
begin
GetWindowRect( AComboBoxListHandle, R );
if R.Right>=Screen.Width then
begin
MoveWindow( AComboBoxListHandle, SaveRight-(R.Right-R.Left)-1, R.Top,
R.Right-R.Left, R.Bottom-R.Top, True );
end;
end;
function HookCallbackFunction(nCode: Integer; wParam: LongInt; lParam: LongInt): Integer; stdcall;
var
wNotifyCode: Integer;
Control: TWinControl;
ListHandle: LongInt;
begin
Result := CallNextHookEx(cwpHandle,nCode,wParam,lParam);
if (Application.Terminated) or (nCode<0) then
Exit;
if nCode=HC_ACTION then
begin
if PCWPStruct(LParam)^.message = WM_COMMAND then
begin
wNotifyCode := HIWORD(PCWPStruct(LParam)^.wParam);
if wNotifyCode = CBN_DROPDOWN then
begin
Control := FindControl( PCWPStruct(LParam)^.lParam );
if (Control<>nil) and (Control is TComboBox) then
AutoSetComboxDropDownWidth( TComboBox( Control ) );
end;
end
else if PCWPStruct(LParam)^.message = WM_CTLCOLORLISTBOX then
begin
ListHandle := PCWPStruct(LParam)^.lParam;
MoveDropDownListIfNecessary( ListHandle );
end;
end;
end;
initialization
cwpHandle := SetWindowsHookEx( WH_CALLWNDPROC, @HookCallbackFunction, 0, MainThreadID );
finalization
if cwpHandle <> 0 then
UnhookWindowsHookEx( cwpHandle );
end.
unit ini akan menset semua combobox sesuai karakter terpanjang
good luck!
more 17 years ago
cyber_hecker
owwww.. wakakak :D, ku pikir DBLookupCombobox itu sama ama ComboBox dalam hal properties :P dan gak sadar kalo yang di minta adalah ComboBox. ya maap :P
more 17 years ago
simba
Kalo dbLookupComboBox bisa seperti itu, logikanya ComboBox biasa juga bisa, toh parent-nya juga sama, TCustomComboBox. Tinggal lihat aja source dbLookupComboBox, gmn dia bisa begitu. Mau? :P
more ...
- Pages:
- 1
- 2
reply |
Report Obsolete
Last Articles
Last Topic
- PascalTalk #6: (Podcast) Kuliah IT di luar negeri, susah gak sih?
by LuriDarmawan in Tutorial & Community Project more 3 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 4 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
- manggil form
by ags606 in Hal umum tentang Pascal Indonesia more 16 years ago - zeos
by suka in Hal umum tentang Pascal Indonesia more 17 years ago - Disable Windows seperti Ctrl+Alt+Del dan Alt+Tab dll.
by IdrisZZ in Network, Files, I/O & System more 15 years ago - Format Waktu
by galih in Tip n Trik Pemrograman more 17 years ago - Bingung antara alias dan databasename ?????
by fadhlanasri in Paradox more 16 years ago - SQL Server does not exist or access denied
by flamade in Hal umum tentang Pascal Indonesia more 17 years ago - bikin preview mata uang gmn?
by skyblue in Tip n Trik Pemrograman more 17 years ago - ospek
by Alfando in OOT more 16 years ago - Ada yang pernah pake SQLLite???
by n3o_cybertech in Lain-lain more 16 years ago - ubah registry komputer lain lewat komputer kita
by gatotkaca in Network, Files, I/O & System more 15 years ago