>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