Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview DynamicBackColor

Status
Not open for further replies.

khalid1963

Programmer
Jan 7, 2015
3
JO
Dear Experts
Is there any way to change the treeview back color based on a condition like DynamicBackColor property for the grid.
Best regards


 
There is no VFP treeview control, so what treeview are you using?

Since all treeviews are COM classes, there is no way to use a DBF or cursor as rowsource, you add node objects and there is no need and no way theere would be a DYNAMICxyz property for these.
Universalthread offers some grid based treeview, that indeed has dynamicbackcolor, because it IS a grid.
ExGrid is a Grid/Treeview component I use has ItemBackcolor.

As far as I googled the the mscomctl Treeview backcolor can be set via SendMessage (Windows messaging), the essential thing to do is
Code:
SendMessage(TreeView1.hWnd, TVM_SETBKCOLOR, 0, RGB(255, 0, 0))
Where SendMessage is a Windows API function you declare as in and TVM_SETBKCOLOR is a constant you should declare as value 4381.

Bye, Olaf.
 
If you are referring to the Microsoft Treeview Control ver 6, which comes with VFP, then the short answer is No. This is essentially the same treeview that was used in some versions of the Windows shell. The way to alter its colours was through Control Panel. I have never tried to do the SendMessage method that Olaf suggests, but I do know that there are no native colour properties for the Treeview Control.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Not exactly what you are asked, but what you can easily access are the node's ForeColor and BackColor properties.
Code:
PUBLIC oFrm
ofrm=CREATEOBJECT("MyForm")
oFrm.Show()

DEFINE CLASS MyForm as Form
	width=600
	height=420
	ADD OBJECT teeview as olecontrol WITH oleclass="Mscomctllib.treectrl.2",width=400,height=400
	
	PROCEDURE init
		CREATE CURSOR mydata(sno n(3),cont_code	n(3),country	c(20),city_code n(6),	city c(20),	name_code n(10),names c(20))
			INSERT INTO mydata values(1,124,	'Pakistan',	124006,	'Bahawalpur',	1240060001,	'BASHIR AHMAD')
			INSERT INTO mydata values(2,124,	'Pakistan',	124006,	'Bahawalpur',	1240060003,	'JAM M HASHIM')
			INSERT INTO mydata values(3,124,	'Pakistan',	124006,	'Bahawalpur',	1240060015,	'YASEEN')
			INSERT INTO mydata values(4,124,	'Pakistan',	124054,	'Lahore',	1240540001,	'AZHAR SHARIF')
			INSERT INTO mydata values(5,124,	'Pakistan',	124068,	'Multan',	1240680001,	'ABDUL REHMAN')
			INSERT INTO mydata values(6,124,	'Pakistan',	124068,	'Multan',	1240680002,	'SYED KASHIF HAMEED')
			INSERT INTO mydata values(7,275,	'Japan',	275001,	'Tokyo',	2750010001,	'WANG YONG')
			INSERT INTO mydata values(8,275,	'Japan',	275001,	'Tokyo',	2750010002,	'IKATO SHI')
			INSERT INTO mydata values(9,275,	'Japan',	275002,	'Nagasaki',	2750020001,	'IGANA YATCHI')
			INSERT INTO mydata values(10,275,	'Japan',	275002,	'Nagasaki',	2750020002,	'HIKO RAMA')
			INDEX on sno TAG sno


		LOCAL lcIdCo,lcIdCi,lnCurrentCountry,lnCurrentCity,loNode
		c1=SYS(2015)
		c2=SYS(2015)
		SELECT distinct cont_code ,country FROM mydata INTO CURSOR (c1)
		SELECT distinct city_code ,city,cont_code FROM mydata INTO CURSOR (c2)

		SELECT (c1)
		SCAN
			lnCurrentCountry = cont_code
			lcIdCo=SYS(2015)
			loNode=thisform.TeeView.Nodes.Add(, 1, lcIdCo,STR(cont_code,3)+" "+ALLTRIM(Country))
			loNode.ForeColor=RGB(255,0,0)
			loNode.BackColor=RGB(223,255,223)
			loNode.Tag=-1
			SELECT (c2)
			SCAN FOR cont_code=lnCurrentCountry
				lnCurrentCity = city_code
				lcIdCi=SYS(2015)
				loNode=thisform.TeeView.Nodes.Add(lcIdCo, 4, lcIdCi,STR(city_code,6)+" "+ALLTRIM(City))
				loNode.ForeColor=RGB(0,255,0)
				loNode.BackColor=RGB(32,0,0)
				loNode.Tag=-1
				
				
				SELECT mydata
				SCAN FOR cont_code=lnCurrentCountry AND city_code=&c2..city_code
					loNode=thisform.TeeView.Nodes.Add(lcIdCi, 4, SYS(2015),STR(name_code)+" "+names)
					loNode.ForeColor=RGB(0,0,255)
					loNode.Tag=sno
					SELECT mydata
				ENDSCAN
				SELECT (c2)
			ENDSCAN
			SELECT (c1)
		ENDSCAN

		FOR EACH loNode IN thisform.TeeView.Nodes && expands all
			loNode.expanded=.T.
		NEXT
	ENDPROC
ENDDEFINE

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
Vilhelm-Ion,

I was tempted to suggest Khalid use the node's properties, but I hesitated because that would only change the colours of the node itself, not the entire tree. Still, it might prove acceptable. Let's see what he says.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I agree with both of you.
But that properties are very easy to set, and resembles to DynamicBackColor.

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top