A user on the message board asked a question about populating a tree control on an Xdialog with a large amount of data.
It turned out that he had a table of zip codes (43000 records) and he wanted to populate a tree control showing states, then cities, then zip codes.
It was taking 7 seconds to populate the tree control.
The technique below shows how you can populate the tree control dynamically. The Xdialog opens instanteously showing a list of states.
Only when you expand a state node are the entries for that state fetched.
This technique is also explained in the 'Learning Xdialog' sample database.
To run this example, you must have the 'zipcode' table (which Alpha sells).
data = "AK,AL,AP,AR,AS,AZ,CA,CO,CT,DC,DE,FL,FM,GA,GU,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MH,MI,MN,MO,MP,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,PW,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY"
data = comma_to_crlf(data)
data = *for_each(x,x + "^!expand_"+x,data)
ui_dlg_box("states",
[%X;S=BRL;D="^"%.40,10selected^
|;
[.40selected];
[.40a_dlg_button];
%dlg%,
if left(a_dlg_button,7) = "expand_" then
tempstate = word(a_dlg_button,2,"expand_")
tempstate_expanded = get_state_data(tempstate)
'ui_msg_box("",tempstate_expanded)
data = stritran(data,tempstate + "^!" + a_dlg_button,tempstate_expanded)
a_dlg_button = ""
end if
%code%)
function get_state_data as c (state as c )
get_state_data = table.external_record_content_get("zipcode","alltrim(city)+'^'+alltrim(zip)","","state=" + quote(state))
get_state_data = alltrim(*for_each(x,state + "^" + x , get_state_data))
'ui_msg_box("",get_state_data)
end function
It turned out that he had a table of zip codes (43000 records) and he wanted to populate a tree control showing states, then cities, then zip codes.
It was taking 7 seconds to populate the tree control.
The technique below shows how you can populate the tree control dynamically. The Xdialog opens instanteously showing a list of states.
Only when you expand a state node are the entries for that state fetched.
This technique is also explained in the 'Learning Xdialog' sample database.
To run this example, you must have the 'zipcode' table (which Alpha sells).
data = "AK,AL,AP,AR,AS,AZ,CA,CO,CT,DC,DE,FL,FM,GA,GU,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MH,MI,MN,MO,MP,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,PR,PW,RI,SC,SD,TN,TX,UT,VA,VI,VT,WA,WI,WV,WY"
data = comma_to_crlf(data)
data = *for_each(x,x + "^!expand_"+x,data)
ui_dlg_box("states",
[%X;S=BRL;D="^"%.40,10selected^
|;
[.40selected];
[.40a_dlg_button];
%dlg%,
if left(a_dlg_button,7) = "expand_" then
tempstate = word(a_dlg_button,2,"expand_")
tempstate_expanded = get_state_data(tempstate)
'ui_msg_box("",tempstate_expanded)
data = stritran(data,tempstate + "^!" + a_dlg_button,tempstate_expanded)
a_dlg_button = ""
end if
%code%)
function get_state_data as c (state as c )
get_state_data = table.external_record_content_get("zipcode","alltrim(city)+'^'+alltrim(zip)","","state=" + quote(state))
get_state_data = alltrim(*for_each(x,state + "^" + x , get_state_data))
'ui_msg_box("",get_state_data)
end function
Comment