Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

Loading Excel file names to combobox

vb.net 2003

What I need:
To load excel file names to a combo box

Form1
cboFileLoad



Thanks
fordraiders
Avatar of vbturbo
vbturbo
Flag of Denmark image


' to add item to combo
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       
       Dim ExcelFile As String
       Dim FindFiles() As String = Directory.GetFiles("C:\What_ever_Folder\", "*.xls")' filter only excel files  *.xls

        For Each ExcelFile In FindFiles
       ComboBox1.Items.Add(ExcelFile )

      Next
    End Sub


vbturbo
Avatar of Fordraiders

ASKER

do I need to add a reference  ?

for

Directory.GetFiles("C:\What_ever_Folder\", "*.xls")' filter only excel files  *.xls

Directory.GetFiles   <-----does not like this

Thanks for replying
Imports System.IO

this should do it

vbturbo
it says "directory" is not declared..

I put  Imports System.IO

in  Assembly.info  Correct ?

Sorry but coming from vb6  

The same here -)
Imports System.IO

is a name space so you can access all IO operations in that particular class.
Here is an example

Imports System
Imports System.IO
Imports System.Data.OleDb


Public Class SomeClass

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim ExcelFile As String
       Dim FindFiles() As String = Directory.GetFiles("C:\What_ever_Folder\", "*.xls")' filter only excel files  *.xls

        For Each ExcelFile In FindFiles
       ComboBox1.Items.Add(ExcelFile )

      Next
    End Sub

    Private Sub btnspecial_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnspecial.Click
        Dim infoform As New special
        infoform.ShowDialog()
    End Sub
End Class
Or it would be better to say

Imports System.IO

is a namespace so you can access  IO operations  - in that namespace with all the classes it contains.
ASKER CERTIFIED SOLUTION
Avatar of vbturbo
vbturbo
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

u can also directly use the VB Turbo Code with
[I have just written the Namespace before the Directory class have a look at it]
[in this case u don't have to import the Namespace]

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim ExcelFile As String
        Dim FindFiles() As String = System.IO.Directory.GetFiles(urFolderPath, "*.xls") ' filter only excel files  *.xls

        For Each ExcelFile In FindFiles
            ComboBox1.Items.Add(ExcelFile)
        Next

    End Sub

Try It

sorry i was 3 mins late to post the same comment have a look at the same comment by vbturbo
thumbs up manch -:)

all relevant inputs and second opinions are important to get an as detailed explanation as posible to the asker.

vbturbo
manch, vbturbo..

Worked fine now!
Except I do not need to see the dir path in the combo box.

I need the code to tell me where its at but I do not need to see the dir path in the box.

Thanjks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks to all very very great stuff...