Matt_Unsworth
asked on
Another simple ListView Question
I've got data being returned from a database into a ListView.
How do I enable the ListView so that I can click on an item in it; and it will select that item ready for an action.
i.e. in Windows Explorer you could, for example highlight a file stored on C:\ and then go up to the Edit menu and perform an action on it like COPY.
I have several different blocks of data being returned and displayed in the ListView.
I would love some code and some instructions for the above
Cheers,
Matt.
How do I enable the ListView so that I can click on an item in it; and it will select that item ready for an action.
i.e. in Windows Explorer you could, for example highlight a file stored on C:\ and then go up to the Edit menu and perform an action on it like COPY.
I have several different blocks of data being returned and displayed in the ListView.
I would love some code and some instructions for the above
Cheers,
Matt.
ASKER
Ok, the actual highlighting of an item in the ListView is part of the functionality of the control.....agreed
I suppose my question is: once an item is selected how do I get a MenuItem or Toolbar button to perfrom its function on the item in the ListView that is selected.
Cheers,
Matt.
PS: just read my original question and no doubt it is a clear as mud.
I suppose my question is: once an item is selected how do I get a MenuItem or Toolbar button to perfrom its function on the item in the ListView that is selected.
Cheers,
Matt.
PS: just read my original question and no doubt it is a clear as mud.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi, Paulstamp <smile>..
Adding to your answer would be the Listview1_Itemclick event which can be used to take action upon the users mouse click.
More advanced methods, are the Listview1_Mousedown and istview1_Mouseup events, combined with a hit test.
Please keep in mind, if the Listview utilizes multi-selection, then your Selected Item will only return the last item clicked on. For multiselection, you have to iterate through the Item collection to find all Items that are applicable.
Gotta tell ya this Paul.. we work hard for the points.. A whole big 10 points here.. don't spend it all in one place.. LOL.
Good seeing ya again Paul.. <smile>.
Adding to your answer would be the Listview1_Itemclick event which can be used to take action upon the users mouse click.
More advanced methods, are the Listview1_Mousedown and istview1_Mouseup events, combined with a hit test.
Please keep in mind, if the Listview utilizes multi-selection, then your Selected Item will only return the last item clicked on. For multiselection, you have to iterate through the Item collection to find all Items that are applicable.
Gotta tell ya this Paul.. we work hard for the points.. A whole big 10 points here.. don't spend it all in one place.. LOL.
Good seeing ya again Paul.. <smile>.
Matt,
If I understand you correctly, you want to be able to identify an item selected in a list and work with it further on.
The first thing is to uniquely identify each row in your database table which feeds the listview (in Access this could be the standard primary key in a table). Store this ID in the ItemData property of each row in your list.
sub ListLoad(c as control, vsTable as string)
dim ttmp as recordset
c.clear
set ttmp = [database].openrecordset(" select * from [table]")
while not ttmp.eof
c.addItem "" & ttmp("...")
c.dataItem(c.newIndex) = ttmp("ID")
ttmp.moveNext
wend
whenever an item is selected you can get the unique identifier of the selected item by using this function:
function CurID(c as control)
if c.ListINdex <> -1 then
CurID = c.ItemData(c.listIndex)
else
CurID = -1
end if
end function
on the click event of a menu item you could add the following code:
dim tmpID as long
tmpID = CurID([ListView])
if tmpID <> -1 then
frmWhatever.Modify tmpID
end if
Hope this is what you where looking for.
If I understand you correctly, you want to be able to identify an item selected in a list and work with it further on.
The first thing is to uniquely identify each row in your database table which feeds the listview (in Access this could be the standard primary key in a table). Store this ID in the ItemData property of each row in your list.
sub ListLoad(c as control, vsTable as string)
dim ttmp as recordset
c.clear
set ttmp = [database].openrecordset("
while not ttmp.eof
c.addItem "" & ttmp("...")
c.dataItem(c.newIndex) = ttmp("ID")
ttmp.moveNext
wend
whenever an item is selected you can get the unique identifier of the selected item by using this function:
function CurID(c as control)
if c.ListINdex <> -1 then
CurID = c.ItemData(c.listIndex)
else
CurID = -1
end if
end function
on the click event of a menu item you could add the following code:
dim tmpID as long
tmpID = CurID([ListView])
if tmpID <> -1 then
frmWhatever.Modify tmpID
end if
Hope this is what you where looking for.
ASKER
Points going to PaulStamp
ASKER
Adjusted points from 10 to 30
ASKER
Cheers PaulStamp your advice was really helpful.
Apologies at the delay in allocating the points.
Matt.
Apologies at the delay in allocating the points.
Matt.
ASKER
Cheers paulstamp, your advice was really helpful.
Apologies in the delay in allocating the points.
Matt.
Apologies in the delay in allocating the points.
Matt.
Not a problem.
The selected item will can be referenced with :
listview1.selecteditem.
Could you clarfiy what you're trying to do exactly ?