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

x
?
Solved

Validation - Listview (lvwreport)

Posted on 2000-04-27
8
Medium Priority
?
764 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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Suggested Courses

610 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