TOPIC: Change the "query" property in ExplorerListView?
#1114
Change the "query" property in ExplorerListView? 2 Years, 6 Months ago
Is it possible to change the query property in an ExplorerListView or ExplorerVirtualListView control? If so, what sort of syntax can be used for that?
 
 
#1115
Re:Change the "query" property in ExplorerListView 2 Years, 6 Months ago
Heh. Figured this one out on my own. My ExplorerVirtualListView's properties can be accessed as (objectname).ExplorerVirtualListView_propname. So if the ExplorerVirtualListView control is named "brwsr", and I want to change the query property, I use .brwsr.ExplorerVirtualListView_query = "query". :D
 
 
#1120
Re:Change the "query" property in ExplorerListView 2 Years, 6 Months ago
That will change the data, but it is "cheating". The problem is that there is probably other things that have to be changed if you change the query (e.g. the columns). That's why you normally need to call a method rather than just change a private data member.
 
 
andrew
 
#1122
Re:Change the "query" property in ExplorerListView 2 Years, 6 Months ago
What method, though? There's no method I can find to call to change the query, unless I change the model using the NewModel() method. And doing that, I have to give a complete list of columns, which seems to be a touch unreasonable.
 
 
#1129
Re:Change the "query" property in ExplorerListView 2 Years, 6 Months ago
Doesn't look like there is a method - you'd have to add one. You can see what SetWhere does to change the query.

Why do you need to change the query? Maybe there is another way to do what you want.
 
 
andrew
 
#1130
Re:Change the 2 Years, 6 Months ago
andrew wrote:
Doesn't look like there is a method - you'd have to add one. You can see what SetWhere does to change the query.

Why do you need to change the query? Maybe there is another way to do what you want.


My application that I'm building does a search on a database table. I'm using it to keep track of my library of books. When I do a search using my search form, I then need to change the query on the ExplorerListView so that it shows the new search results. I could do this by having the results display in a new window, or better, a dialog.
 
 
#1132
Re:Change the 2 Years, 6 Months ago
If I undestood it correctly you only need to alter the where clause, it can be done using SetWhere

Code:


On_Lookup()
{



key=.FindControl('keyfield').Get()

lookup=.FindControl('lookup').Get()


if key == 'name'
where= lookup is ''? '': 'where name =~ "(?i)'$lookup$'"'

else
where= lookup is ''? '': 'where user =~ "(?i)'$lookup$'"'

.lv.SetWhere(where)
}


Where lv is a reference for your listview, you can obtain such reference
in the new method of your controller


Code:


New()
{
.curPanel=0
.lv=.FindControl('lv')
.vw=.lv.GetView()

}





Note the use of findcontrol, find control finds a control by its name so when you build your screen it's a good idea give them names

Code:



Controls:
(Vert
Skip
(Horz Fill (ComboBox 'name' 'user' set:'user' name:'keyfield') Skip (FieldHistory name:'lookup') Skip (Button 'Lookup')Skip)
(ExplorerListViewControl name:'lv'
#("ExplorerListModel", "users" ("user"') (user name))
#(Form
(user group:0) nl
(name group:0) nl
(password group:0) (new_password) nl
(duedate tabstop:false group:0) nl
(enabled group:0) nl
(Button 'New') (Button 'Delete')
(Button 'Reset Password' group:0)nl nl

)
query: "users"
columns: #(user name enabled)
title: " "
noShading:true
status:true

validField:'UsersWorkWith_valid'
protectField:'UsersWorkWith_protect'

)
)




Note the name:'lv'

I've used this technique to build this screen


The complete source code is
Code:



Controller
{
Title:'Work with Users'
Commands:
(
(Change_View, "Ctrl+Tab", "Change View"')
)

DefaultButton:'Lookup'
Controls:
(Vert
Skip
(Horz Fill (ComboBox 'name' 'user' set:'user' name:'keyfield') Skip (FieldHistory name:'lookup') Skip (Button 'Lookup')Skip)
(ExplorerListViewControl name:'lv'
#("ExplorerListModel", "users" ("user"') (user name))
#(Form
(user group:0) nl
(name group:0) nl
(password group:0) (new_password) nl
(duedate tabstop:false group:0) nl
(enabled group:0) nl
(Button 'New') (Button 'Delete')
(Button 'Reset Password' group:0)nl nl

)
query: "users"
columns: #(user name enabled)
title: " "
noShading:true
status:true

validField:'UsersWorkWith_valid'
protectField:'UsersWorkWith_protect'

)
)
New()
{
.curPanel=0
.lv=.FindControl('lv')
.vw=.lv.GetView()

}
On_Lookup()
{



key=.FindControl('keyfield').Get()

lookup=.FindControl('lookup').Get()


if key == 'name'
where= lookup is ''? '': 'where name =~ "(?i)'$lookup$'"'

else
where= lookup is ''? '': 'where user =~ "(?i)'$lookup$'"'

.lv.SetWhere(where)
}
On_Reset_Password()
{

lv=.FindControl('lv')
vw=lv.GetView()

query="users where user =~'(?i)"$Suneido.User
if Query1(query) is false
{
Alert('You need *SECADM authority to do this')
return
}
pass = Ask(prompt:'New Password' title:'Resetting password' ctrl:#(Field password:true))

if pass isnt false
{
vw.SetField('password',Md5(vw.GetField('user').Upper()$pass))
vw.SetField('duedate',Date())
vw.SetField('enabled',true)
}
}
On_Change_View()
{
switch .curPanel
{
case 0:
.lv.GetList().SetFocus()
case 1:
.lv.GetView().SetFocus()
default:
.FindControl('keyfield').SetFocus()
.curPanel=-1
}
.curPanel++
}

}



Hope it helps

Post edited by: sanotto, at: 2008/02/12 23:59