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

How to fill 2 Listboxes on a form based on 1 dbf.file 2

Status
Not open for further replies.

german12

Programmer
Nov 12, 2001
563
DE
I have a form with 2 listboxes which are to be filled.
The name of the dbf.file as a source is GOOGLEA.dbf
It has the following structure:

Field-Name1................... Field-name2
Kategorie ....................... Begriff
Flowers............................ rose
Flowers............................ tulip
Flowers............................ sun-flower

Listbox List1 should show only the distinct(kategorie) - that is in this example only once the item "flowers"
when the user clicks on it - it will do something.

Listbox List2 should show the details - that is in this example a list with 3 items (rose, tulip, sunflower) and when the user clicks eg. on "rose" something the programm should do.

How are the entries for Listbox1 and Listbox2 for
a)the control-source
b)rowsource
c)row-source types

A small code snippet would help me a lot.
I tried it, but had always problems
Thanks in advance

Klaus


Peace worldwide - it starts here...
 
There are several ways of doing this. Here is one possible approach:

In the Init of Listbox 1:

Code:
SELECT DISTINCT Kategorie FROM GOOGLEA INTO CURSOR csrList1
THIS.RowsSourceType = 2
THIS.RowsSource = "csrList1"
THIS.ListIndex = 1

In the InteractiveChange of Listbox 1:

Code:
SELECT Begriff FROM GOOGLEA WHERE ALLTRIM(Kategori) = csrList1.Kategorie ;
  INTO CURSOR csrList2
THIS.Parent.ListBox2.RowSourceType = 2
THIS.Parent.ListBox2.RowSource = "csrList2"

No doubt you'll get other - perhaps better - suggestions.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
One possibility.

Code:
PUBLIC ofrm
ofrm = CREATEOBJECT("MyForm")
ofrm.show()

DEFINE CLASS MyForm as Form
	cKat = SYS(2015)
	cBeg = SYS(2015)
	ADD OBJECT list1 as listbox WITH RowSourceType = 3, RowSource = "SELECT DISTINCT Kategorie FROM GOOGLEA INTO CURSOR " + ThisForm.cKat + " READWRITE"
	ADD OBJECT list2 as listbox WITH left = 150, RowSourceType = 3, RowSource = "SELECT Begriff Kategorie FROM GOOGLEA WHERE Kategorie = " + ThisForm.cKat + ".Kategorie INTO CURSOR " + ThisForm.cBeg + " READWRITE"
	PROCEDURE load
		CREATE CURSOR GOOGLEA (Kategorie C(25), Begriff C(25))
		INSERT INTO GOOGLEA VALUES ('Flowers','rose')
		INSERT INTO GOOGLEA VALUES ('Flowers','tulip')
		INSERT INTO GOOGLEA VALUES ('Flowers','sun-flower')
		INSERT INTO GOOGLEA VALUES ('Fruits','apple')
		INSERT INTO GOOGLEA VALUES ('Fruits','peach')
		GO TOP IN GOOGLEA
	ENDPROC
	PROCEDURE list1.click
		ThisForm.list2.Requery
	ENDPROC
ENDDEFINE

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

 
The simplest is to USE the same table twice with different ALIAS names.

Bye, Olaf.
 
What Olaf said has made me wonder if have understood the question.

Klaus, did you mean that you want Listbox 2 to show the records that match the selection in Listbox 1? In other words, if you select "Flowers" in Listbox 1, then Listbox 2 will show all the flowers; if you select "Fruit" in Listbox 1, then Listbox 2 will show all the fruit; and so on. If so, then my suggestion should work.

But if the two listboxes are independent; one shows the distinct categories, the other shows all records, regardles of the category; then my suggestion for the first listbox should still work; for the second one, you would use the table again with a different alias, as Olaf suggested, and then use that new alias as the record source for Listbox 2.

Perhaps you could clarify this point.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Sorry Mike, for confusing you. I wasn't paying attention to the details.

I thought of a case showing same options twice, for example as categorizing the topic of a question with two sections of a forum, you'd need same options twice, but if you bind the same table twice the listbox1 selection will be reflected in lstbox2. You simply need two aliases to have two record pointers. I thought of this problem, because it's not so easy to get, when you're not thinking about the nature of workareas and record pointers.

But it could still be a solution combined with SET FILTER on the second alias. Needing to show two different parts of a table you can also go with the other solutions and split data the way they do, the data should preexist split anyway. You avoid redundancy, so you'd have main and subcategories, maybe just categories, but with an optional reference to a parentcategoryID, whoch makes all categories without a parentId to root an main elements and allows subsubcategories or any further sub level, too. In such cases a treeview would be the natural control to use. You'd have 1 FLOWERS NULL and 2 rose 1, 3 tulip 1, 4 sun-flower 1 each point to the main category.

Bye, Olaf.
 
Mike,
Klaus, did you mean that you want Listbox 2 to show the records that match the selection in Listbox 1? In other words, if you select "Flowers" in Listbox 1, then Listbox 2 will show all the flowers; if you select "Fruit" in Listbox 1, then Listbox 2 will show all the fruit; and so on. If so, then my suggestion should work.

that is exactly what I meant - and meanwhile you code runs well. Thank you so far.

There is only one small thing left: When the form is initiated, then Listbox 1 ist automatically filled with the categories (Flowers or Fruit etc.)
that is o.k. - but then I have first to CLICK at least on one of the items in Listbox 1 in order to see also the details to be shown in Listbox 2.
No big problem - but if at start a "simulated" click on Listbox1 (eg. on the 1. Listbox-item) could be coded then the user can see, what kind of details are behind a category in the detailed Listbox 2.

However, I do not know, how this can be done.

Regards
Klaus

Form1_zw2fuw.png
Form2_jijvh3.png


Peace worldwide - it starts here...
 
@Tamar - thank you very much for the Advisor article dated June 2006 titled: "Cascading combos and lists " - and yes - that is mainly what my app should do.(eg. clicking on a category like "flowers" should show ALL flowers, and in a second listbox the individual types (roses, tulips) can be shown. Both information come from one free table with two fields (category and details). I hope that clarifies my thread.
Regards from Germany
Klaus


Peace worldwide - it starts here...
 
There is only one small thing left: When the form is initiated, then Listbox 1 ist automatically filled with the categories (Flowers or Fruit etc.)
that is o.k. - but then I have first to CLICK at least on one of the items in Listbox 1 in order to see also the details to be shown in Listbox 2.

That's easy to solve. Just copy the code I gave you for the InteractiveChange, and paste just after the code I gave you for the Init. In other words, you "simulate" an interactive change when the listbox is instantiated.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
@Mike: That was great! Now the program fullfills so far all requirements I had.
Additionally it is understandable for an old newbie like me. Thank you very much. As you could see, meanwhile I added a pageframe to the form, which allows to look not only for things by category or detail but also can distinguish between something was created in watercolor, coal, acrylic oder oil. The program will consider now for these painting methods to find paintings or drawings which cover this method.
Thank you so much!

Klaus



Peace worldwide - it starts here...
 
It seems you really used the pageframe tabs only. If you like, you can also have the grey background of the pageframes, if you send it to back. Keep all pages empty and have the two listboxes in front , though they are not part of the pages, but on the main form. Then switching pages only switches the filter you set or the query you do to get the Category and Details matching the Picture Artwork type.

In german:

Es scheint so, als hast Du nur die Reiter des Seitensteuerelements genutzt. Wenn Du magst, kannst Du auch so tun, als wären die Listen wirklcih auf den Seiten, ziehe das Seitensteuerelement groß und sende es in den Hintergrund, dann passiert beim blättern trotzdem nichts, weil die Listen nicht auf einer Seite liegen, sondern trotzdem noch auf dem Formular, sie liegen nur rein optisch in der Seite. Das wechseln der Seite kann dann im Activate Ereignis trotzdem noch den Filter setzen oder die Abfrage machen, nur die für den Kunstwerktyp gültigen Kategorien und Details zu holen.

Tschüß, Olaf.
 
@Olaf:
Beim Klicken meines Programms öffnen sich Internetseiten via Hyperlink-object, das heißt, nach dem Klick ist nur noch ein Seite im Internet sichtbar, die die Anforderungen erfüllt (z.B. eine Rose in Aquarell gemalt).
Dann ist natürlich meine Form überhaupt nicht sichtbar, erst wenn der Internetbildschirm wieder geschlossen ist, taucht meine Form wieder auf.
Deshalb muss ich ja eigentlich nichts am Aussehen ändern, oder?
Aber - vielen Dank - Dein Vorschlag ist dennoch für ein anderes Project nützlich, welches ich vorhabe.

english:
When the user clicks on the Listboxes immediately[highlight #FCE94F] a desired Web Screen opens caused by a Hyperlink which is included in my Form.[/highlight][highlight #FCE94F][/highlight] So one can only see the homepage, which is in accordance with what is required to see. (eg. a rose painted with watercolor, or a drawed with a pencil etc.)
So my own form will not be visible, as long as one does not close the webside.
Therefore I would not change the form as it is now.
[highlight #FCE94F]But thanks for your advice, because that could be meaningful in another planned project, so I am glad to know it now.
[/highlight]
Bye
Klaus


Peace worldwide - it starts here...
 
Makes total sense. Actually it's a matter of taste, whether a greyish gradient or the the blue colored background looks better.

It may just look more professional to have the listboxes appearing on the pages, even though they just appear to be in there. You can mix this, eg have a list on the left side actually child objet of the form and each page is empty in that area, but has detals on the right side differing per page. It means no need to bind data N times with N workareas or have any flicker or other unwanted effeft in bind/unbind.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top