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!

Treeview control populating

Status
Not open for further replies.

kumar1248

IS-IT--Management
Feb 12, 2012
2
US
Hi
I need to display two trees in an access form. The first tree has Questions(nodes with check

boxes),ex:Q1,Q2,Q3,Q4,Q5,Q6....Qn. In an example case If the user selects Q1,Q2,Q3,Q4 then i need to come up with

second tree called fields selection Tree where in which the parent nodes are permutations and combinations(power set) of
Questions selected.
In this case
Q1Q2Q3Q4,Q1Q2Q3,Q1Q3Q4,Q1Q2Q4,Q2Q3Q4,Q1Q2,Q1Q3,Q1Q4,Q2Q3,Q2Q4,Q3Q4,Q1,Q2,Q3,Q4.So its basically 2powerN -1
combinations (for 4 questions selected , its 15 parent nodes in second tree,if its 5 then 2pwr5-1=32-1=31 parent
nodes in second tree). Q1Q2 is same as Q2Q1.I need to display 4s combinations,3s combinations,2s and then 1 in decreasing order.But the real problem is here. Under node
Q1Q2Q3Q4 i need to display fields that are common to all Q1Q2Q3Q4 and under the fields as many number of nodes to
number of Questions(i.e. again Q1,Q2,Q3,Q4 as 4 grand children nodes). Under Q1Q2Q3 parent , display fields(children nodes) common to Q1Q2Q3 only
(it should not show field common to all 4 again) and Q1,Q2,Q3 under it(grand children repeat for each field) and so on. To explain this, continue the
same example
For Q1, Fields F1,F2,F3,F4,F5,F6,F7 are available
For Q2: F1,F2,F3,F8,F9,F10,F11,F12
Q3: F1,F3,F6,F10,F13,F14,F15,F16
Q4: F1,F9,F6,F17,F18,F19,F20

SO the second(fields selection) tree should show like this (check box style)
Q1Q2Q3Q4
--F1
-Q1
-Q2
-Q3
-Q4
--Fx(if Fx is common to all Q1Q2Q3Q4)
again all 4 under Field x (Fx)
-Q1
-Q2
-Q3
-Q4

Q1Q2Q3
--F3(common to Q1Q2Q3 ONLY,should not show F1 , even though its common to Q1Q2Q3 because it is already shown in
the Q1Q2Q3Q4 combination)
-Q1
-Q2
-Q3
Q1Q3Q4
--F6 (fields common to Q1Q3Q4 only)
-Q1
-Q3
-Q4
Q1Q2Q4
-- fields common to Q1Q2Q4 only
then
-Q1
-Q2
-Q4
-- fields common to Q1Q2Q4 only
then
-Q1
-Q2
-Q4
Q2Q3Q4
--fields common to Q2,Q3,Q4 only
-Q2
-Q3
-Q4
--fields common to Q2,Q3,Q4 only
-Q2
-Q3
-Q4
Q1Q2
--F1

--F2
--F3

Q1Q3
--F1
--F3
--(NO F6 here..because its already out there under Q1Q3Q4 )
Q1Q4
---
Q2Q3
Q2Q4
Q3Q4
Q1
Q2
Q3
Q4
--
and so on. No Question(Parent) node if there are no common fields for that combiation of questions.

I went up to Powerset creation, finding common fields between Question combinations, but not able to filter for
displaying Fields common to that combination ONLY..(yes, the "ONLY" is very important here).

I have a lot hope that somebody will help me in this forum. Please.. please help....
 
First of all this is incorrect and does not make sense:
parent nodes are permutations and combinations(power set)
See thread 701-1673713.
You do not have permutations you have only combinations because order does not matter. What you have is the enumeration of all combinations without replacement of N question numbers choosen R at a time for R = 1 to N.

So as the thread shows you could find the question nodes using sql. In code you would build (1 to N) query definitions as shown for doing combinations without replacement for N choose R.

I have a module that I built instead where I can pass in an array and R and it returns an array of all combinations for N choose R. You could call this function in a loop from 1 to N and that would create all the nodes.

For the second part it has hard to say how I would do it without seeing how the data is stored. Not sure how in a properly designed datbase questions could have fields. My first recommendation is fix the database. If different questions have multiple fields I can guarantee this database is not properly designed. If this is normalized I should be able in sql to union the questions and fields and return the list of distinct fields (assuming fields are now records). Then loop the list of fields and run a query for each to return the related questions, do this for each field.

If you do not normalize it, I would use some techniques like in Thread705-1673848 to find the unique fields and the Unique questions per field.


In order to help you will need to provide more detail on the table structure. I have most of the code to do this, it should not be too hard, but this is one you are going to have to post a test set of data. I use 4shared.com to post links to database, but use any file share site.

 
Thank you MajP.
Yes.It may be called as Combinations.I wrote that function already.
But for the 2nd part,
sorry for the confusion. Basically its not that a question has fields stored in one table. when user selects a question(s) , set of fields(information)can be offered thru 2nd tree. These set of fields can be overlapped with other questions.Its up to user to select fields whatever he want from 2nd Tree. Instead of repeating same(common) fields for every question, Fields/information offering will be minimized by grouping common fields.That is the intention.
In the example i have taken for Q1:F1,F2..F7 just for explanation.Its not that all these fields are from a single table.
I got struck at 2nd Part. Please help.
 
You still have to explain how the information is organized.

It sounds like you have all parent nodes. So lets say I read a parent node with a Key of
Q1,Q2
I split the Key into two strings Q1, and Q2. If I knew how the data is organized I could come up with a way to get all the "fields" associated with Q1 and all the fields associated with Q2. But right now I have no idea if those are fields or records in a related table, and what to return. Maybe this can be a query, maybe its code.

But I would probably do something like this. I would return a query with Q1 and all related fields. I would loop this information and populate a collection. Storing "Q1" and in the Tag store the field name. Do the same for Q2.

Now above I have a collection with all questions and all fields. Now to get all unique fields I would loop the above collection and Probably use a dictionary object for speed. If the key does not exist add that key to the dictionary (field Name), add a collection in the dictionary for that key that holds questions.

So if both Q1 and Q2 have F1 the dictionary would have a key of
"F1" and contain a collection that holds two items (Q1, Q2)

Now load the tree. Enumerate the dictionary. Read the first key "F1". Add that to the node as a child. Return the associated collection for that key enumerate that and add the field child nodes, Q1, Q2.

Although that approach is pretty flexible, that does not ensure that the keys are sorted. Would need to add a way to sort the keys efficiently.

However, I prefer to do this using sql. But without knowing how the data is structured cannot guess. If I can return a recordset with all distinct fields for q1 and q2 (and better yet sorted). I read those fields and add them as child nodes. Then return another recordset of all fields for q1 and q2 sorted by field then question. Now can just read that pull the field name and question. Add the question to the field.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top