Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Auto set ColumnWidths Property for Comboboxes?
Message
From
22/08/2000 10:41:54
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00407724
Message ID:
00407747
Views:
27
>I am trying to use TXTWIDTHS() function to determine my ColumnWidths of my Combobox. I get some numbers like 21, 36, 30 for various items in the rows in my drop-down list, but I can't seem to figure out how to or where to or when to put the largest of those value in order to use it to set my combobox column width.
>
>I tried changing my Form to Foxels instead of Pixels, but no help. The weird thing is if I set my ColumnWidths property to a number like 150 foxels when I first click on the combobox it appears that the drop-down list is only as wide as my combobox, but if I select an item from the drop-down list and then click on the combobox, I see a somewhat wider drop-down list, but not wide enough to show my longest item.
>
>What's wrong? I would like to auto set the column width but I can't use Builder because my comboboxes are populated using arrays. The arrays are populating fine, I just can't get the column widths as wide as I need them. I alltrim all of the entries in my arrays so they are preset to be the correct size at Form Init time for my comboboxes.
>
>TIA!


Hi Steve,
You could calculate it say at init of form. As a sample suppose you have a combo1 on form with rowsource is set to thisform.myArray and content come from employee. :
With thisform
  Select last_name, first_name, emp_id from employee into array .myArray
  For ix = 1 to alen(.myArray,2)
    Store 0 to ('lnColWidth'+padl(ix,3,'0'))
  Endfor
  lcFont = .Fontname
  lnFontSize = .Fontsize
  For ix=1 to alen(.myArray,1)
    For jx = 1 to alen(.myArray,2)
      Store ;
        max(eval('lnColWidth'+padl(jx,3,'0')),;
        txtwidth(trim(.myArray[ix,jx]),lcFont,lnFontSize)*fontmetric(6,lcFont,lnFontSize)) ;
        to ('lnColWidth'+padl(jx,3,'0'))
    Endfor
  Endfor
  lcColumnWidths = ''
  For ix = 1 to alen(.myArray,2)
    lcColumnWidths = lcColumnWidths + iif(empty(lcColumnWidths),'',',')+;
      ltrim(str(eval('lnColWidth'+padl(ix,3,'0'))))
  Endfor
  .Combo1.Columncount = alen(.myArray,2)
  .Combo1.ColumnWidths = lcColumnWidths
Endwith
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform