Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking if File1 Box is selected...

Status
Not open for further replies.

perlone

Programmer
May 20, 2001
438
US
How do I check to see if the user have selected a file from the File1 box? I want to disable the command "Delete" button, if they have not selected any item from the File1 box. Thank you for your time. There is no Knowledge that is not power.
Age: 17
E-mail: projectnet01@yahoo.com
Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
the control should have a ListIndex property that would be equal to -1 if no item is selected
 
You could also set the command button's enabled property to false then enable it in the file listbox's click event:
Code:
Private Sub File1_Click()

    Command1.Enabled = True

End Sub

Then when the button is clicked, disable it again:
Code:
Private Sub File1_Click()

    If MsgBox("Delete this file?", vbQuestion + vbYesNo, "Delete File") = vbYes Then

        'Confimed
        'Code to delete file
        
        'Disable button - it will be
        'enabled again if user clicks another file
        Command1.Enabled = True
    
    End If 'User clicks 'Yes'

End Sub

This should ensure that the button is only enabled when they click a file name.

Hope this helps

Daren
Must think of a witty signature
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top