Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 To: Samir H.
  Where is Samir H.?
 Yogyakarta
 Indonesia
 Samir H.
 Tags
Subject: RE: Newbee and AddProperty form method
Thread ID: 288908 Message ID: 288957 # Views: 54 # Ratings: 2
Version: Visual FoxPro 9 SP2 Category: Forms
Date: Monday, December 27, 2010 10:59:11 AM         
   


> > Hi Gerald,
> >
> >
> >
> > You're welcome.
> >
> >
> > As a matter of taste, I'd put everything belonging to a certain object into methods of that very object/class, so that it would be kind-of encapsulated, and could even be reused as a separate class on several forms.
> >
> > However, if you want to use SQL, perhaps combo.RowSourceType=3 might be an option - you can put the SQL statement directly into the RowSource property in the Properties window if you like, so that perhaps an additional SQL Union can provide the desired "Not Found" row-source row.
> > (Although I'd add that row only if the users should have that one as an interactive. Whereas if it's just for the display value, the VFP combo-box class would display an empty value for invalid control-source values automatically, even if there is no "empty" row in the row source.)
> >
> > So that your SQL, i.e. the combo.RowSource string might look like:
> >
> > SELECT Distinct city From yourTable UNION Select '(N/A)' FROM yourTable Into Cursor Sys(2015)
> > 

> >
> > (I agree with Anders though, instead of the "Select Distinct city From customers", I would put the the cities (as well as the states) into separate, "normalized" tables, so that the customers table you mentioned would have a foreign-key column pointing to the primary key of the cities table.)
> >
> >
> > For what it's worth, on the combobox.RowSourceType topic, see also the runnable demo.PRG showing a few different combo.RowSourceType approaches pasted below the signature.
> > (It's using "Define Class" syntax so that it can get copied directly from the browser, although in a real project, I'd probably use the visual Class/Form designers.
> >
> >
> >
> > hth
> > -Stefan
> >
> >
> >
> > PUBLIC loForm as Form
> > loForm = CREATEOBJECT('TestForm')
> > loForm.Show()
> > RETURN
> > 
> > DEFINE CLASS TestForm as Form
> > 	AutoCenter = .T.
> > 	AllowOutput = .F.
> > 	nCountryID = 1
> > 
> > 	PROCEDURE Load
> > 		LOCAL lnSelect
> > 		lnSelect = SELECT(0)
> > 		CREATE CURSOR countries (cou_id I, cou_name C(30))
> > 		SELECT (m.lnSelect)
> > 		INSERT INTO countries VALUES (1, "France")
> > 		INSERT INTO countries VALUES (2, "United Kingdom")
> > 		INSERT INTO countries VALUES (3, "U.S.A.")
> > 	ENDPROC
> > 
> > 	ADD OBJECT cboCountry0 as Combobox WITH ;
> > 		Left = 50, Top = 80, Width = 150, Style = 2, ;
> > 		BoundTo = .T., BoundColumn = 2, ;
> > 		ControlSource = 'Thisform.nCountryID', ;
> > 		RowSourceType = 0
> > 	PROCEDURE cboCountry0.Init()
> > 		This.Requery()
> > 	ENDPROC
> > 	PROCEDURE cboCountry0.Requery()
> > 		This.Clear()
> > 		LOCAL lnSelect
> > 		lnSelect = SELECT(0)
> > 		SELECT cou_name, cou_id FROM countries INTO CURSOR temp
> > 		This.AddItem('')
> > 		This.AddListItem('0',This.NewItemID,2)
> > 		SCAN
> > 			This.AddItem(cou_name)
> > 			This.AddListItem(TRANSFORM(cou_id),This.NewItemID,2)
> > 		ENDSCAN
> > 	ENDPROC
> > 
> > 	ADD OBJECT cboCountry6 as Combobox WITH ;
> > 		Left = 50, Top = 120, Width = 150, Style = 2, ;
> > 		BoundTo = .T., BoundColumn = 2, ;
> > 		ControlSource = 'Thisform.nCountryID', ;
> > 		RowSourceType = 6, ;
> > 		RowSource = 'countries.cou_name, cou_id'
> > 	PROCEDURE cboCountry6.Init
> > 		This.AddItem('')
> > 		This.AddListItem('0',This.NewItemID,2)
> > 		This.Requery()
> > 	ENDPROC
> > 
> > 	ADD OBJECT cboCountry3 as Combobox WITH ;
> > 		Left = 50, Top = 160, Width = 150, Style = 2, ;
> > 		BoundTo = .T., BoundColumn = 2, ;
> > 		ControlSource = 'Thisform.nCountryID', ;
> > 		RowSourceType = 3, ;
> > 		RowSource = ;
> > 			[SELECT cou_name, cou_id FROM countries ] + ;
> > 			[UNION SELECT '', 0 FROM countries ] + ;
> > 			[INTO CURSOR SYS(2015)]
> > 
> > 	ADD OBJECT cboCountry5 as Combobox WITH ;
> > 		Left = 50, Top = 200, Width = 150, Style = 2, ;
> > 		BoundTo = .T., BoundColumn = 2, ;
> > 		ControlSource = 'Thisform.nCountryID'
> > 	PROCEDURE cboCountry5.Init()
> > 		This.AddProperty('aRowSource[1]')
> > 		This.Requery()
> > 		This.RowSourceType = 5
> > 		This.RowSource = 'This.aRowSource'
> > 	ENDPROC
> > 	PROCEDURE cboCountry5.Requery()
> > 		SELECT cou_name, cou_id FROM countries INTO ARRAY (This.aRowSource)
> > 		DIMENSION This.aRowSource[ ALEN(This.aRowSource,1)+1, 2 ]
> > 		This.aRowSource[ ALEN(This.aRowSource,1), 1 ] = ''
> > 		This.aRowSource[ ALEN(This.aRowSource,1), 2 ] = 0
> > 	ENDPROC
> > 
> > ENDDEFINE
> > 

>
> Hi Stefan
> I often see people using sys(2015) for a cursor name. Did you do it here just because it is a sample, or do you use that in your own code as well? Why not just take a meaningful name, i.e. crsStates, so we'd have a good overview when using the datasession window? Is there any good reason to use sys() in real code (except to avoid duplicate names when creating tons of cursors) ?
>
> Regards
> Samir

Actually in this case (RowSourcetype=3-SQL) I also prefer using a meaningful name like crsStates. Because using something like that, instead of using cboMyCombo.Value, I can directly check crsStates.StateAbbr or crsStates.StateName and so on (any column of cursor, whether it is part of columns or not and no datatype conversion is needed). ie: It might be:

select * from orders where country = 'USA' into cursor crsOrders

with columncount = 2 and I could simply check crsOrders.Order_Amt or crsOrders.Order_date for the selected record.

Cetin Basoz

.Net has got better.Think about moving - check my blog:
Blog (main)
Blog (mirror)

ENTIRE THREAD

Newbee and AddProperty form method Posted by Gerald Fay @ 12/25/2010 9:27:55 PM
RE: Newbee and AddProperty form method Posted by Stefan Wuebbe @ 12/25/2010 11:15:20 PM
RE: Newbee and AddProperty form method Posted by Gerald Fay @ 12/26/2010 6:33:49 PM
RE: Newbee and AddProperty form method Posted by Stefan Wuebbe @ 12/26/2010 9:02:07 PM
RE: Newbee and AddProperty form method Posted by Samir H. @ 12/27/2010 2:22:52 AM
RE: Newbee and AddProperty form method Posted by tushar @ 12/27/2010 5:11:48 AM
RE: Newbee and AddProperty form method Posted by Stefan Wuebbe @ 12/27/2010 10:56:04 AM
RE: Newbee and AddProperty form method Posted by Samir H. @ 12/27/2010 11:57:12 AM
RE: Newbee and AddProperty form method Posted by Ony Too @ 12/27/2010 2:13:01 PM
RE: Newbee and AddProperty form method Posted by Samir H. @ 12/27/2010 2:56:32 PM
RE: Newbee and AddProperty form method Posted by Ony Too @ 12/28/2010 6:36:49 AM
RE: Newbee and AddProperty form method Posted by Samir H. @ 12/28/2010 8:03:04 AM
RE: Newbee and AddProperty form method Posted by Cetin Basoz @ 12/27/2010 10:59:11 AM
RE: Newbee and AddProperty form method Posted by Samir H. @ 12/27/2010 11:54:00 AM
RE: Newbee and AddProperty form method Posted by Cetin Basoz @ 12/27/2010 6:04:34 PM
RE: Newbee and AddProperty form method Posted by Gerald Fay @ 12/27/2010 7:08:38 AM
RE: Newbee and AddProperty form method Posted by Stefan Wuebbe @ 12/27/2010 11:25:32 AM
RE: Newbee and AddProperty form method Posted by Jun Tangunan @ 12/28/2010 3:40:59 AM
RE: Newbee and AddProperty form method Posted by Samir H. @ 12/28/2010 3:54:37 AM
RE: Newbee and AddProperty form method Posted by Stefan Wuebbe @ 12/28/2010 7:33:01 AM
RE: Newbee and AddProperty form method Posted by Jun Tangunan @ 12/28/2010 8:05:48 AM
RE: Newbee and AddProperty form method Posted by Stefan Wuebbe @ 12/28/2010 10:28:42 AM
RE: Newbee and AddProperty form method Posted by Jun Tangunan @ 12/29/2010 12:19:48 AM
RE: Newbee and AddProperty form method Posted by Cetin Basoz @ 12/29/2010 1:41:27 AM
RE: Newbee and AddProperty form method Posted by Jun Tangunan @ 12/29/2010 2:11:57 AM
RE: Newbee and AddProperty form method Posted by Stefan Wuebbe @ 12/29/2010 2:20:14 PM
RE: Newbee and AddProperty form method Posted by Cetin Basoz @ 12/29/2010 2:39:39 PM
RE: Newbee and AddProperty form method Posted by Samir H. @ 12/29/2010 3:08:48 PM
RE: Newbee and AddProperty form method Posted by Cetin Basoz @ 12/30/2010 9:32:09 AM
RE: Newbee and AddProperty form method Posted by Jun Tangunan @ 12/29/2010 11:42:07 PM
RE: Newbee and AddProperty form method Posted by Gerald Fay @ 12/28/2010 8:25:03 AM
RE: Newbee and AddProperty form method Posted by Stefan Wuebbe @ 12/28/2010 10:31:14 AM
RE: Newbee and AddProperty form method Posted by Ony Too @ 12/26/2010 6:00:33 AM
RE: Newbee and AddProperty form method Posted by Gerald Fay @ 12/27/2010 2:01:43 AM
RE: Newbee and AddProperty form method Posted by Cetin Basoz @ 12/27/2010 10:51:52 AM
RE: Newbee and AddProperty form method Posted by Anders Altberg @ 12/26/2010 7:20:37 PM
RE: Newbee and AddProperty form method Posted by Jun Tangunan @ 12/28/2010 3:44:21 AM
RE: Newbee and AddProperty form method Posted by Gerald Fay @ 12/28/2010 8:55:49 AM
RE: Newbee and AddProperty form method Posted by Anders Altberg @ 12/29/2010 5:23:29 PM
RE: Newbee and AddProperty form method Posted by Jun Tangunan @ 12/29/2010 11:57:08 PM
RE: Newbee and AddProperty form method Posted by Anders Altberg @ 12/30/2010 10:12:32 AM
RE: Newbee and AddProperty form method Posted by Jun Tangunan @ 12/28/2010 6:31:22 AM
RE: Newbee and AddProperty form method Posted by Gerald Fay @ 12/28/2010 8:37:18 AM
RE: Newbee and AddProperty form method Posted by Ron Seidl @ 2/16/2014 4:54:41 PM