Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Listbox


  • Please log in to reply
7 replies to this topic

#1 heltune

heltune

  • Members
  • 59 posts
  • OFFLINE
  •  
  • Local time:05:30 AM

Posted 09 September 2008 - 12:08 AM

hello ... how can i add double click event on the listbox to open any file in visual basic.... and im also having a command button to open it as an alternate to the double click event from the same listbox.... is it possible? how?
can you give me a simple code...

thank you.... god bless po...

Edited by heltune, 09 September 2008 - 12:09 AM.


BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:02:30 AM

Posted 09 September 2008 - 05:43 AM

Yep.

Sub Actionsyouwant()
'Code here
Listbox1.selecteditem...
End Sub

Sub somefunc() handles Listbox1.click
Actionsyouwant()
End Sub

Sub somefunc2() handles CommandButton.click
Actionsyouwant()
End Sub
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 Keithuk

Keithuk

  • Members
  • 957 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:10:30 AM

Posted 09 September 2008 - 06:23 AM

hello ... how can i add double click event on the listbox to open any file in visual basic.... and im also having a command button to open it as an alternate to the double click event from the same listbox.... is it possible? how?
can you give me a simple code...

You haven't said which VB you are using and Billy's reply isn't very clear

You can combine the two events to the ListBox. I don't have VB at work but its something like this in VB6 :thumbsup:
Private Sub ListBox1_Dblclick()

'If you double click the ListBox text then click the button code
Command1_Click

End Sub

Private Sub Commnd1_Click()

'What ever you want to do the the text in the ListBox, show what you have clicked
MsgBox ListBox1.List(ListBox1.ListIndex)

End Sub

Edited by Keithuk, 09 September 2008 - 06:25 AM.

Keith

Windows ME (spare computer)
Windows XP 2002 Professional SP3 (desktop computer)
Windows 7 Professional SP1 32bit (laptop computer)

Windows 8 64bit spare drive for laptop computer


#4 heltune

heltune
  • Topic Starter

  • Members
  • 59 posts
  • OFFLINE
  •  
  • Local time:05:30 AM

Posted 09 September 2008 - 10:54 AM

im using VB 6.o

what i want to my listbox is that i want to open the file listed on it by double clicking... let us say the list contains all of my word documents i want that when i double click the filename (example a word doc.) it will open and work on it...

the command button will also be used as an alternative in opening the files in the listbox.... is it possible?
i was able to do it on my filelistbox and i want it if possible on listbox/// is it possible?
thank you...

#5 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:02:30 AM

Posted 09 September 2008 - 02:05 PM

Sorry.. I was a little rushed this morning ;)

You can simply create a function that opens the word doc based on the currently selected item in the listbox.

You can then call the one function with both the button.click event, and the listbox.doubleclick events.

You can start word itself with something like

Shell("winword """ + filevar + """")

Does that help?

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#6 heltune

heltune
  • Topic Starter

  • Members
  • 59 posts
  • OFFLINE
  •  
  • Local time:05:30 AM

Posted 10 September 2008 - 09:55 AM

thank you guys for the help i got answers from one website that is Andra VB website... thank you for the help...

GOD BLESS... bleeping computer helps a lot to aspiring programmers as well as newbies like me... Salamat po!

#7 Keithuk

Keithuk

  • Members
  • 957 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:10:30 AM

Posted 11 September 2008 - 06:57 AM

im using VB 6.o

what i want to my listbox is that i want to open the file listed on it by double clicking... let us say the list contains all of my word documents i want that when i double click the filename (example a word doc.) it will open and work on it...

the command button will also be used as an alternative in opening the files in the listbox.... is it possible?
i was able to do it on my filelistbox and i want it if possible on listbox/// is it possible?
thank you...


Well all you need is the full path to the file and filename in the ListBox the easiest way to do this is to use a DriveListBox and a FileListBox with the Pattern set to *.doc. Then the other easy way to open and type of registered file is to use the ShellExecute API. When I say registered file I mean *.txt are registered to NotePad, *.doc are registered to Winword, *.pdf are registered to Adobe32 etc. Now that means you have to have Winword installed as part of office else WordPad will try open it

You can simply create a function that opens the word doc based on the currently selected item in the listbox.

You can then call the one function with both the button.click event, and the listbox.doubleclick events.

You can start word itself with something like

Shell("winword """ + filevar + """")


Your still talking VB.Net Billy you don't need to Shell anything you just ShellExecute the filename. :flowers:

I'll give you another tip for VB6 users, download API-Guide it gives loads of examples how to use API calls and there are a few in there for VB.Net and its a free. While you are there you can download and install a newer API Viewer because the VB6 one is 10 years old and thats free as well. :thumbsup:

Edited by Keithuk, 11 September 2008 - 06:58 AM.

Keith

Windows ME (spare computer)
Windows XP 2002 Professional SP3 (desktop computer)
Windows 7 Professional SP1 32bit (laptop computer)

Windows 8 64bit spare drive for laptop computer


#8 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:02:30 AM

Posted 11 September 2008 - 01:51 PM

Your still talking VB.Net Billy you don't need to Shell anything you just ShellExecute the filename. :flowers:

I'll give you another tip for VB6 users, download API-Guide it gives loads of examples how to use API calls and there are a few in there for VB.Net and its a free. While you are there you can download and install a newer API Viewer because the VB6 one is 10 years old and thats free as well. :thumbsup:

Hmmm found that on what claimed to be a VB6 website... shell is not legal in .NET either.

In .net it's System.Diagnostics.Process.Start()

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users