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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List box data display problem after calling with change data

Status
Not open for further replies.

mstrcmtr

Programmer
Nov 14, 2007
103
PK
Select Item_Code , Item_Name , Item_on_Hand_Qty where CC = 'USA' INTO Cursor Cursor1

thisform.List1.RowSourceType = 6
thisform.List1.RowSource = 'Cursor1.Item_Code,Item_Name,Item_on_Hand_Qty'
thisform.List1.BoundTo = .T.
thisform.List1.BoundColumn = 1

Now

WITH thisform.List1 As ListBox
lcRowSource = .RowSource
.RowSource = ''
ENDWITH

e.g.

Re make the Cursor again

Select Item_Code , Item_Name , Item_on_Hand_Qty where CC = 'GER' INTO Cursor Cursor1

WITH thisform.List1 As ListBox
.RowSource = lcRowSource
.Refresh()
.Requery()
ENDWITH

If Directly focus the List box from other control after executing with change filters on data List box shows empty no record when move the down arrow key in list box it start shwoing records in List box

IF not Focus List1 then it shows the new records
 
Hi,

You may want to set RowSourceType to 3 and add the desired SQL statement. If you omit to Select ... INTO something a browse window appears when the SQL SELECT statement is executed. Or you may want to set RowSourceType = 5 and populate the array accordingly (see code below)

Code:
PUBLIC goForm

goForm = CREATEOBJECT("MyForm")
goForm.Show()

READ EVENTS

CLOSE ALL
CLEAR ALL 

**********

DEFINE CLASS MyForm as Form
	DIMENSION laCountries[1]
	cCountry = ""
	
	Width = 540
	Height = 360
	MinWidth = This.Width
	MinHeight = This.Height
	MaxWidth = This.Width
	AutoCenter = .T.
	ShowTips = .T.
	Themes = .F.
	
	ADD OBJECT opgChoice as OptionGroup WITH ;
		Top = 12, ;
		Left = ThisForm.Width - 60, ;
		ButtonCount = 3, ;
		Value = 1, ;
		AutoSize = .T., ;
		Anchor = 9
		
		PROCEDURE opgChoice.Init()
			LOCAL loButton
			
			FOR i = 1 TO This.ButtonCount
				WITH This.Buttons(i)
					.AutoSize = .T.
					.Caption = ICASE(i = 1, "US", i = 2, "FR", "DE")
				ENDWITH 
			ENDFOR 
		ENDPROC 
		
		PROCEDURE opgChoice.Click()
			DO CASE 
				CASE This.Value = 1
					ThisForm.cCountry = "US"
				
				CASE This.Value = 2
					ThisForm.cCountry = "FR"
				
				CASE This.Value = 3
					ThisForm.cCountry = "DE"
				
			ENDCASE 
			
			ThisForm.lstList.Init()
			
		ENDPROC 

	ADD OBJECT lstList as ListBox WITH ;
		Top = 12, ;
		Left = 12, ;
		Width = ThisForm.Width - 84, ;
		Height = ThisForm.Height - 24, ;
		Anchor = 15, ;
		RowSourceType = 5, ;
		RowSource = "ThisForm.laCountries", ;
		ColumnCount = 3, ;
		ColumnWidths = "60, 90, 42", ;
		BoundTo = .T., ;
		BoundColumn = 1
		
		PROCEDURE lstList.Init()
			Select cItemCode, cItemName, iQuantity FROM csrOne WHERE cCountry = ThisForm.cCountry INTO ARRAY ThisForm.laCountries

			This.Requery()
			
		ENDPROC 
		
	PROCEDURE Load()
		CREATE CURSOR csrOne (cItemCode C(5), cItemName C(15), iQuantity I, cCountry C(2))
		
		INSERT INTO csrOne VALUES ("AAAAA", "GMG X1", 5, "US")
		INSERT INTO csrOne VALUES ("AAAAB", "GMG Y2", 4, "US")
		INSERT INTO csrOne VALUES ("AAAAC", "Renault Zoe", 5, "FR")
		INSERT INTO csrOne VALUES ("AAAAD", "Renault Twizzy", 3, "FR")
		INSERT INTO csrOne VALUES ("AAAAE", "Renault Twingo", 7, "FR")
		INSERT INTO csrOne VALUES ("AAAAF", "BMW 3", 5, "DE")
		INSERT INTO csrOne VALUES ("AAAAG", "BMW 5", 5, "DE")
		INSERT INTO csrOne VALUES ("AAAAH", "VW Golf", 5, "DE")
		INSERT INTO csrOne VALUES ("AAAAI", "Ausi A7", 5, "DE")
			
	PROCEDURE Destroy()
		CLEAR Events
		ThisForm.Release
		
	ENDPROC
ENDDEFINE

hth

marK
 
Put the code to create whatever the listbox is based on in the listbox's Requery method. Then, call Requery from the Init and again whenever you want to update the data.

Tamar
 
Hi,

Below a working demo for RowSourceType = 6

Code:
PUBLIC goForm

goForm = CREATEOBJECT("MyForm")
goForm.Show()

READ EVENTS

CLOSE ALL
CLEAR ALL 

**********

DEFINE CLASS MyForm as Form
	cCountry = "US"
	
	Width = 480
	Height = 270
	MinWidth = This.Width
	MinHeight = This.Height
	MaxWidth = This.Width
	Caption = "Cars on Stock"
	AutoCenter = .T.
	ShowTips = .T.
	Themes = .F.
	
	ADD OBJECT opgChoice as OptionGroup WITH ;
		Top = 12, ;
		Left = ThisForm.Width - 60, ;
		ButtonCount = 6, ;
		Value = 1, ;
		AutoSize = .T., ;
		Anchor = 9
		
		PROCEDURE opgChoice.Init()
			LOCAL loButton
			
			FOR i = 1 TO This.ButtonCount
				WITH This.Buttons(i)
					.AutoSize = .T.
					.Caption = ICASE(i = 1, "US", i = 2, "FR", i = 3,"DE", i = 4, "GB", i = 5, "IT", "All")
				ENDWITH 
			ENDFOR 
		ENDPROC 
		
		PROCEDURE opgChoice.Click()
			DO CASE 
				CASE This.Value = 1
					ThisForm.cCountry = "US"
				
				CASE This.Value = 2
					ThisForm.cCountry = "FR"
				
				CASE This.Value = 3
					ThisForm.cCountry = "DE"
				
				CASE This.Value = 4
					ThisForm.cCountry = "GB"
				
				CASE This.Value = 5
					ThisForm.cCountry = "IT"
				
				CASE This.Value = 6
					ThisForm.cCountry = ""
				
			ENDCASE 
			
			ThisForm.lstList.Init()
			
		ENDPROC 

	ADD OBJECT lstList as ListBox WITH ;
		Top = 12, ;
		Left = 12, ;
		Width = ThisForm.Width - 84, ;
		Height = ThisForm.Height - 24, ;
		Anchor = 15, ;
		RowSourceType = 6, ;
		RowSource = "cItemCode, cItemName, iQuantity", ;
		ColumnCount = 3, ;
		ColumnWidths = "54, 96, 42", ;
		BoundTo = .T., ;
		BoundColumn = 1
		
		PROCEDURE lstList.Init()
			Select cItemCode, cItemName, iQuantity FROM csrOne WHERE cCountry = ThisForm.cCountry INTO CURSOR csrVanish

			This.Requery()
			
		ENDPROC 
		
	PROCEDURE Load()
		CREATE CURSOR csrOne (cItemCode C(5), cItemName C(15), iQuantity I, cCountry C(2))
		
		INSERT INTO csrOne VALUES ("AAAAA", "GMG X1", 5, "US")
		INSERT INTO csrOne VALUES ("AAAAB", "GMG Y2", 4, "US")
		INSERT INTO csrOne VALUES ("AAAAC", "Renault Zoe", 12, "FR")
		INSERT INTO csrOne VALUES ("AAAAD", "Renault Twizzy", 3, "FR")
		INSERT INTO csrOne VALUES ("AAAAE", "Renault Twingo", 17, "FR")
		INSERT INTO csrOne VALUES ("AAAAF", "BMW 3", 15, "DE")
		INSERT INTO csrOne VALUES ("AAAAG", "BMW 5", 25, "DE")
		INSERT INTO csrOne VALUES ("AAAAH", "VW Golf", 51, "DE")
		INSERT INTO csrOne VALUES ("AAAAI", "Audi A7", 14, "DE")
		INSERT INTO csrOne VALUES ("AAAAJ", "Austin", 11, "GB")
		INSERT INTO csrOne VALUES ("AAAAK", "Triumph", 9, "GB")
		INSERT INTO csrOne VALUES ("AAAAL", "Morgan", 9, "GB")
		INSERT INTO csrOne VALUES ("AAAAM", "Alfa Romeo", 6, "IT")
		INSERT INTO csrOne VALUES ("AAAAN", "Fiat", 5, "IT")
		INSERT INTO csrOne VALUES ("AAAAO", "Maserati", 2, "IT")
			
	PROCEDURE Destroy()
		CLEAR Events
		ThisForm.Release
		
	ENDPROC
ENDDEFINE

hth

marK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top