Solved

Validation - Listview (lvwreport)

Posted on 2000-04-27
8
722 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now