Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Another simple ListView Question

Posted on 2000-03-03
10
Medium Priority
?
154 Views
Last Modified: 2012-05-04
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.
0
Comment
Question by:Matt_Unsworth
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 3

Expert Comment

by:paulstamp
ID: 2579427
I'm not sure I understand the question - you appear to be asking how to let the user click on an item and highlight it - which is intrinsic behaviour of the control.

The selected item will can be referenced with :

listview1.selecteditem.

Could you clarfiy what you're trying to do exactly ?
0
 

Author Comment

by:Matt_Unsworth
ID: 2579464
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.
0
 
LVL 3

Accepted Solution

by:
paulstamp earned 120 total points
ID: 2579494
I'm still not 100% clear, but I think you're looking for something like this

Dim ltmTarget as listitem

set ltmtarget = listview1.selecteditem

msgbox "Selected item is " & ltmtarget.text

Basically you can set listitem object to point to the selecteditem within the listview and manipulate it's properties like that, or pass it around within your program.

Hope that is of some help.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 14

Expert Comment

by:wsh2
ID: 2579538
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>.



0
 

Expert Comment

by:rudiger
ID: 2583809
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.
0
 

Author Comment

by:Matt_Unsworth
ID: 2635288
Points going to PaulStamp
0
 

Author Comment

by:Matt_Unsworth
ID: 2635293
Adjusted points from 10 to 30
0
 

Author Comment

by:Matt_Unsworth
ID: 2635294
Cheers PaulStamp your advice was really helpful.

Apologies at the delay in allocating the points.

Matt.
0
 

Author Comment

by:Matt_Unsworth
ID: 2635298
Cheers paulstamp, your advice was really helpful.

Apologies in the delay in allocating the points.

Matt.
0
 
LVL 3

Expert Comment

by:paulstamp
ID: 2636478
Not a problem.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question