Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can't add a combobox to a grid programatically
Message
From
15/11/2002 15:35:27
 
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Miscellaneous
Thread ID:
00723342
Message ID:
00723406
Views:
8
>Don,
>
>Any chance you could show us the code you use to add the combo to the grid?

no problem

this.aGridFields is an array containing each grid field in a row of the array. The columns are
*!* this.cFieldNameCol = 1 && field name ie eqno
*!* this.cFieldCaptionCol = 2 && field caption ie Equip. no.
*!* this.cFieldWidthCol = 3 && field display width - 10 in chars
*!* this.cDefaultControlCol = 4 && default control ie agridctrl.grdtext
*!* this.lFieldReadOnly = 5 && is field read only

interresting for us is the section headed by :
** see if there is a custom control

My problem occurs at :
oColumn.AddObject(cConName,cClass)
local cConName,nSeekField,cClass,cClassLibrary,nTabIndex,nHeight
local nLeft,nWidth,nTop,lcFontStyle,nAverCharWidth,nCols
local oColumn,oControl,oGrid,lTallControl
nSeekField = iif(this.lSeekCol,1,0) && 0 if seek field not used
oGrid          = eval("this.grdTableList")
cClass         = oGrid.Class
cClassLibrary  = justfname(oGrid.ClassLibrary)
nTabIndex      = oGrid.TabIndex
nHeight        = oGrid.Height
nLeft          = oGrid.Left
nWidth         = oGrid.Width
nTop           = oGrid.Top

lcFontStyle    = util.FontStyle(oGrid) && function in zUtil
nAverCharWidth = fontmetric(6,oGrid.FontName,;
					oGrid.FontSize,lcFontStyle)
nCols          = alen(this.aGridFields,1)
** set grid properties
oGrid.ColumnCount      = nCols + nSeekField
oGrid.TabIndex         = nTabIndex
oGrid.Height           = nHeight
oGrid.Left             = nLeft
oGrid.Width            = nWidth
oGrid.Top              = nTop
oGrid.RecordSource     = thisform.PrimaryTable
select (thisform.PrimaryTable)
oGrid.ReadOnly         = .f.
oGrid.RecordSourceType = 1
set classlib to aGrdCtrl additive
** setup a seek column if required
if this.lSeekCol 
	oGrid.Column1.Name = "NdxColumn"
	oGrid.NdxColumn.BackColor = RGB(255,255,128)
	oGrid.NdxColumn.Header1.Caption = this.cOrderCaption
	oGrid.NdxColumn.ControlSource = alltrim(this.cOrderExp)
	oGrid.NdxColumn.AddObject("InGrid1","ingrid")
	oGrid.NdxColumn.InGrid1.Visible = .t.
	oGrid.NdxColumn.CurrentControl = "InGrid1"
	oGrid.NdxColumn.RemoveObject("Text1")
	* oGrid.Partition = 1
endif
** add columns
for lnColNo = 1+nSeekField to nCols+nSeekField
	nFieldNo = lnColNo - nSeekField
	oColumn = eval("oGrid.Column" + alltrim(str(lnColNo)))
	oColumn.Header1.Caption = this.aGridFields(nFieldNo,this.cFieldCaptionCol)
	** see if there is a custom control
	if not empty(this.aGridFields[nFieldNo,this.cDefaultControlCol]) && have a different control
		** is the custom control from a different class library?
		nPos = at(".",this.aGridFields[nFieldNo,this.cDefaultControlCol]) 
		if nPos > 0
			** from a different classlib
			cClassLib =   left(this.aGridFields[nFieldNo,this.cDefaultControlCol],nPos-1)
			cClass    = substr(this.aGridFields[nFieldNo,this.cDefaultControlCol],nPos+1)
		else
			** from agridctrl
			cClassLib =  "agrdctrl"
			cClass    =  this.aGridFields[nFieldNo,this.cDefaultControlCol]
		endif
		if not (upper(cClassLib)$set("classlib"))
			set classlib to (cClassLib) additive
		endif
		** add the control with the same name as the class
		cConName = cClass+"9"
		oColumn.AddObject(cConName,cClass)
		oColumn.RemoveObject("Text1")
		oControl = eval("oColumn." + cConName)
		if inlist(lower(oControl.BaseClass),"combobox")
			oGrid.RowHeight = 21
		endif
		oControl.Visible = .t.
		oColumn.Sparse   = .t.
		oColumn.CurrentControl = (cConName)
	endif
	oColumn.ControlSource   = ;
		lower(alltrim(this.aGridFields[nFieldNo,;
		this.cFieldNameCol]))
	oColumn.Bound = .t.
	oColumn.Width = this.aGridFields(nFieldNo,this.cFieldWidthCol) *;
					 nAverCharWidth
	oColumn.ReadOnly = this.aGridFields(nFieldNo,this.lFieldReadOnly)
*!*		oColumn.Text1.ReadOnly = .f.
endfor

oGrid.Visible = .t.
oGrid.Refresh[]

return
Best Regards
Don Simpson
Previous
Reply
Map
View

Click here to load this message in the networking platform