>******************************************************************** >* Description.......: NNwgGrid.FormatAndSetCaption - format all grid columns and set caption to be in Proper format >* Calling Samples...: >* Parameter List....: >* Created by........: Nadya Nosonovsky 03/09/2000 02:03:22 PM >* Modified by.......: Nadya Nosonovsky 06/12/2002 12:39:18 PM >******************************************************************** >local loColumn, loControl, lnWidthTotal, lnSel, ; > lnFWidth, lnCWidth, lcFieldName, lcFieldType, lcCaption, lcTestName, ; > lcDBC, lcHdrFontStyle, lcFontStyle >lnSel=select() && save current area >store "" to lcHdrFontStyle, lcFontStyle >with this > if .recordsourcetype = 1 or .recordsourcetype = 0 && Alias or table > select (.recordsource) > lnWidthTotal= iif(.recordmark, 10,0)+ iif(.scrollbars>1,sysmetric(5),0) ; > + 2 * .gridlinewidth + iif(.deletemark, 10,0)+10 && record marker & vertical scroll bar+deletion mark > for each loColumn in .columns >* -- For each column determine the width and use the correct caption. >* -- Display the caption via the proper() function. > lcFieldName=justext(loColumn.controlsource) > lcTestName=lower(juststem(dbf(alias()))+"."+m.lcFieldName) > lcFieldType=type(m.lcFieldName) > lnFWidth=iif(m.lcFieldType='D',13,iif(m.lcFieldType='T',28,fsize(m.lcFieldName)+3)) && Field size > lcDBC = set('database') > if !empty(m.lcDBC) and juststem(cursorgetprop('Database',.recordsource)) = m.lcDBC > lcCaption=dbgetprop(m.lcTestName,'field','caption') > if empty(m.lcCaption) && There is no DBC caption, Just use the Field name > lcCaption=proper(m.lcFieldName) > endif > else > lcCaption=proper(m.lcFieldName) > endif > with loColumn > .removeobject('Header1') > .newobject('Header1','MyHeader','MyHeader.prg',,m.lcCaption) && custom header > lcHdrFontStyle = iif(.Header1.fontbold,"B","") + ; > iif(.Header1.fontitalic,"I","")+ ; > iif(.Header1.fontstrikethru,"-","")+ ; > iif(.Header1.fontunderline,"U","") > lcFontStyle = iif(.fontbold,"B","") + ; > iif(.fontitalic,"I","")+ ; > iif(.fontstrikethru,"-","")+ ; > iif(.fontunderline,"U","") > lnCWidth=(txtwidth(.Header1.caption,.Header1.fontname,.Header1.fontsize, m.lcHdrFontStyle)+2) * ; > fontmetric(6,.Header1.fontname,.Header1.fontsize, m.lcHdrFontStyle)+3 && Width of caption > > .width=round(max(m.lnFWidth*fontmetric(6,.fontname,.fontsize, m.lcFontStyle),m.lnCWidth),0) > lnWidthTotal=m.lnWidthTotal+loColumn.width > > if m.lcFieldType='L' && Logical field > if lower(.currentcontrol)='text1' && standard text1 control > .removeobject('text1') > .newobject('check1','wgcheckbox','wgcontrols.vcx') && CheckBox > .check1.caption = '' > .sparse = .t. > .check1.visible=.t. > endif > endif > >** Nadya Nosonovsky 03/29/2000 01:35:47 PM added Incremental Search (could be added for ReadOnly grid) > if this.lIncremental and m.lcFieldType='C' && We would use this feature only for charStyle fields > if lower(.currentcontrol)='text1' && standard text1 control > .removeobject('text1') > if lower(m.lcFieldName)='code' and tagno('code')> 0 and ; > (candidate(tagno('code')) or primary(tagno('code'))) && should be unique > .newobject('text1','nnIngrid','fields_controls.vcx') && Incremental search textbox, which is also unique > thisform.lCheck=.t. && Code value should be unique > .text1.pcFields='code' > .text1.pcValidTag='code' > .text1.cSeekTag='code' > else > .newobject('text1','ingrid','wgcontrols.vcx') && Incremental search textbox > .text1.cLocateExpression='upper('+m.lcFieldName+')' > endif > .text1.visible=.t. > endif > endif > >* Nadya Nosonovsky 03/29/2000 01:36:17 PM added Show Memo > if this.lShowMemo and m.lcFieldType='M' && We want to show Memo field > if lower(.currentcontrol)='text1' && standard text1 control > .removeobject('text1') > .newobject('text1','edtexpand','wgcontrols.vcx') && expandable editbox > .text1.visible=.t. > .sparse=.f. > endif > endif > endwith > endfor > .width=min(.width,m.lnWidthTotal) > endif >endwith >select (m.lnSel) && return to previous area>