if this.recordsourcetype=1 OR this.recordsourcetype=0 && Alias or table select (this.recordsource) lnWidthTotal= iif(this.recordmark, 10,0)+ iif(this.scrollbars>1,sysmetric(5),0) ; + 2 * this.gridlinewidth + iif(this.deletemark, 10,0)+10 && record marker & vertical scroll bar+deletion mark for each loColumn in this.columns * -- For each column determine the width and use the correct caption. * -- Display the caption via the proper() function. lcFieldName=alltrim(substr(loColumn.controlsource,rat('.',loColumn.controlsource)+1)) lcFieldType=type(lcFieldName) lnFWidth=iif(lcFieldType='D',13,iif(lcFieldType='T',28,fsize(lcFieldName)+3)) && Field size for each loControl in loColumn.controls if lower(loControl.baseclass) = "header" * Handle condition of header set in grid. if lower(left(loControl.caption,6))='header' && Don't override a preset caption * -- NSL Use the DBC caption if it exists. loControl.caption=dbgetprop(loColumn.controlsource,'field','caption') endif if empty(loControl.caption) && There is no DBC caption, Just use the Field name loControl.caption=proper(lcFieldName) else loControl.caption=proper(loControl.caption) && If it has been coded in the grid, use it. endif lnCWidth=(txtwidth(loControl.caption,loControl.fontname,loControl.fontsize)+2) * ; fontmetric(6,loControl.fontname,loControl.fontsize)+3 && Width of caption endif exit && No need to ck the other controls endfor loColumn.width=round(max(lnFWidth*fontmetric(6,loColumn.fontname,loColumn.fontsize),lnCWidth),0) lnWidthTotal=lnWidthTotal+loColumn.width