Solved

Validation - Listview (lvwreport)

Posted on 2000-04-27
8
739 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
[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
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

730 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