  | 
				VFP 愛用者社區 本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.   
				 | 
			 
		 
		 
	
		| 上一篇主題 :: 下一篇主題   | 
	 
	
	
		| 發表人 | 
		內容 | 
	 
	
		zfgg
 
 
  註冊時間: 2004-05-31 文章: 179 來自: 中国
  第 1 樓
  | 
		
			
				 發表於: 星期三 十一月 29, 2006 5:18 pm    文章主題: 如何在treeview中显示表中的部分内容? | 
				     | 
			 
			
				
  | 
			 
			
				有一个表单,上面有一个combobox控件和一个 treeview控件。在combobox控件中有很多的条目,每一个条目对应一个treeview控件中键值。当选中某一条目时,读出键值(ccKey),作为treeview控件中最初显示的数据。combobox控件的click event(事件)代码如下:
 
PUBLIC ccKey
 
ccKey=""
 
_stext=alltr(this.value)
 
_cDm=substr(_stext,1,at("-",_stext)-1)
 
_nDm=val(_cDm)
 
_cTm=substr(_stext,at("-",_stext)+1)
 
SELECT cousehead
 
LOCATE FOR charpt=_cTm
 
IF FOUND()
 
ccKey=ALLTRIM(cousehead.key)
 
ELSE
 
RETURN
 
ENDIF
 
 
Thisform.olecontrol1.LineStyle= 1  && tvwRootLines 
 
Thisform.olecontrol1.Style= 7  && tvwTreelinesPlusMinusPictureText 
 
Thisform.olecontrol1.ImageList=Thisform.Imagelist1   &&与Imagelist控件建立关联
 
*Thisform.olecontrol1.SingleSel=.t.
 
SELECT tblPerson
 
   SET DELETED ON 
 
*!*	   SET FILTER TO ALLTRIM(tblPerson.key)=ccKey
 
	o = THISFORM.olecontrol1.Nodes
 
	o.Clear
 
	LOCATE FOR ALLTRIM(tblPerson.parent) = '0_' .AND. ALLTRIM(tblPerson.key)=ccKey
 
IF FOUND()
 
	SCAN
 
		IF ALLTRIM(tblPerson.parent) = '0_'
 
			o.add(,1,ALLTRIM(tblPerson.key),ALLTRIM(题目),1,2)
 
		ELSE
 
			o.add(ALLTRIM(tblPerson.parent),4,ALLTRIM(tblPerson.key), ALLTRIM(tblPerson.题目),3,3)
 
		ENDIF
 
		THISFORM.cNextKey = ALLTRIM(STR(VAL(tblPerson.key) + 1) + "_")
 
*!*	       skip
 
	ENDSCAN
 
 
ENDIF
 
if Thisform.olecontrol1.nodes.count>0
 
Thisform.olecontrol1.selecteditem=Thisform.olecontrol1.nodes(1)
 
Endif
 
 
以上程序执行后,是将tblperson.dbf表中的内容全部显示在treeview控件中。我用过滤条件,SET FILTER TO ALLTRIM(tblPerson.key)=ccKey 但只能显示tblperson.dbf表中的第一条记录,程序就不执行了。
 
tblperson.dbf表的结构如下:
 
key  字符型  4位
 
parent  字符型  4位
 
题目    字符型  60位
 
tblperson.dbf表的记录格式如下:
 
key        parent             题目 
 
1_         0_
 
2_         1_
 
3_         1_
 
4_         2_
 
………………..
 
50_        0_
 
51_        50_
 
52_        51_ 
 
………………..
 
84_        0_
 
85_        84_
 
86_        84_
 
87_        84_
 
88_        51_
 
89_        51_
 
90_        50_
 
 
如果combobox控件中的取值为50_,赋与ccKey,我想只显示key值为 50_ , parent值为 0_的子结点后数据,应如何写代码?请教高手指教,本人诚恳受教。
 
注:程序中的例子是采用张洪举先生的书《Visual foxpro6.0-9.0解决方案与范例大全》 | 
			 
		  | 
	 
	
		| 回頂端 | 
		 | 
	 
	
		  | 
	 
	
		garfield Site Admin
  
  註冊時間: 2003-01-30 文章: 2160
 
  第 2 樓
  | 
		
			
				 發表於: 星期三 十一月 29, 2006 6:07 pm    文章主題:  | 
				     | 
			 
			
				
  | 
			 
			
				SET FILTER TO tblPerson.key==ccKey or tblPerson.parent==ccKey or tblPerson.parent=='0_  '
 
請注意 ccKey 和 '0_  ' 的字串長度是否相等於 key的欄位長度. _________________ 利用>>搜尋<<的功能會比問的還要快得到答案. | 
			 
		  | 
	 
	
		| 回頂端 | 
		 | 
	 
	
		  | 
	 
	
		zfgg
 
 
  註冊時間: 2004-05-31 文章: 179 來自: 中国
  第 3 樓
  | 
		
			
				 發表於: 星期四 十一月 30, 2006 9:11 am    文章主題: 还是没有解决,请再指教. | 
				     | 
			 
			
				
  | 
			 
			
				史兄弟:
 
非常感谢你的解答,有了很大的进步。用以下方法试,真正选中的条目可以显示了,但没有选中的条目,也显示(只显示一行根结点,有子节点的没有显示)。也就是说有多个根结点的第一个数据还是出现。
 
SET FILTER TO alltr(tblPerson.key)==ccKey or alltr(tblPerson.parent)=='0_ '  or alltr(tblPerson.parent)==ccKey
 
 
locate for 语句改为:
 
locate for alltr(tblPerson.parent)=='0_ '  .and. alltr(tblPerson.key)==ccKey .or. alltr(tblPerson.parent)==ccKey
 
 
再请指教。
 
    此致
 
敬礼!
 
zfgg | 
			 
		  | 
	 
	
		| 回頂端 | 
		 | 
	 
	
		  | 
	 
	
		zfgg
 
 
  註冊時間: 2004-05-31 文章: 179 來自: 中国
  第 4 樓
  | 
		
			
				 發表於: 星期四 十一月 30, 2006 9:40 am    文章主題: 又有了进展 | 
				     | 
			 
			
				
  | 
			 
			
				史兄弟: 一
 
我又试了下,有了很大的进步。将
 
SET FILTER TO alltr(tblPerson.key)==ccKey or alltr(tblPerson.parent)=='0_ ' or alltr(tblPerson.parent)==ccKey
 
 
 改为:
 
SET FILTER TO alltr(tblPerson.key)==ccKey and alltr(tblPerson.parent)=='0_ ' or alltr(tblPerson.parent)==ccKey 
 
 
可以只显示选中的条目,其它的根结点不显示了。但是问题又出现了,只显示第一级的子结点,再以下的子结点不显示了。请再帮助分析指教。
 
zfgg | 
			 
		  | 
	 
	
		| 回頂端 | 
		 | 
	 
	
		  | 
	 
	
		 | 
	 
 
  
  	 
	    
  	   | 
 	
您 無法 在這個版面發表文章 您 無法 在這個版面回覆文章 您 無法 在這個版面編輯文章 您 無法 在這個版面刪除文章 您 無法 在這個版面進行投票 您 無法 在這個版面附加檔案 您 無法 在這個版面下載檔案
  | 
   
  
		 |