Solved

Validation - Listview (lvwreport)

Posted on 2000-04-27
8
735 Views
Last Modified: 2013-12-26
Got a listview(lvwreport)showing db data(items). Able to highlight the desired items(selecteditems)then click on the command button(delete)to performed an erase operation.

So, how can i've validation in the command button by prompting an error msg. if there isn't any selection(highlight) in the listview ??
0
Comment
Question by:lightstream
8 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2758390
maybe you can loop through the listitems collection:

Private Sub cmdDelete_Click()
    Dim i As Integer
    For i = 1 To ListView1.ListItems.Count
        If ListView1.ListItems(i).Selected = True Then
            ListView1.ListItems.Remove (i)
        End If
        i = i + 1
    Next
End Sub
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2758392
maybe you can loop through the listitems collection:

Private Sub cmdDelete_Click()
    Dim i As Integer
    For i = 1 To ListView1.ListItems.Count
        If ListView1.ListItems(i).Selected = True Then
            ListView1.ListItems.Remove (i)
        End If
        i = i + 1
    Next
End Sub
0
 

Accepted Solution

by:
morpho earned 100 total points
ID: 2758545
If all you want to do is check to see if there is an item selected, try this :

If Not ListView1.SelectedItem Is Nothing Then
    'Handle Deletion Here
Else
    Msgbox "No Item to delete."
EndIf
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Expert Comment

by:morpho
ID: 2758560
AzraSound - I have a nasty feeling that your code for removing elements will probably fall because your loop may go from 1 to 10 items, but after deleting say item 3, there will be no item 10.

Also... isnt the question how to detect if there is no selection, rather than how to delete items from the listview ?
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2758592
you may be right, i wasnt on a machine with vb to try it out.  however as far as me not answering his question, the way he made it sound, he was getting an error when he tried to delete when nothing was selected.  why else would he want to put an error handler in there? so if my code had worked it would've killed two birds with one stone so to speak.
0
 

Expert Comment

by:morpho
ID: 2758708
AzraSound -

Maybe you're right - I wasnt accusing you of not answering the question - I was just trying to clarify it.

I read it as saying "how do I see if no item is selected so I can warn the user if they hit delete" - I dont think lightstream really means error box -  more a validation message. But I may be wrong.
0
 
LVL 12

Expert Comment

by:jgv
ID: 2759077
Set the listview's HideSelection property to False.

Private Sub ListView1_Click()
    If ListView1.SelectedItem Is Nothing Then
        cmdAllowDelete.Enabled = False
    Else
        cmdDelete.Enabled = True
    End If
End Sub

Private Sub ListView1_KeyDown(KeyCode As Integer, Shift As Integer)
    If ListView1.SelectedItem Is Nothing Then
        cmdDelete.Enabled = False
    Else
        cmdDelete.Enabled = True
    End If
End Sub

Private Sub cmdDelete_Click()
    '
    'delete the list items
    '
    cmdDelete.Enabled = False
End Sub

0
 

Author Comment

by:lightstream
ID: 2759082
Guys...

Sorry..about the misleading words. TQ anyway.
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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

790 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