• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

Add files to a Combo box?

Right now I'm using OpenFileDialog() to view and select Crystal Reports with the following Command Button code:

Private Sub btnSelectReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim dlg As New OpenFileDialog
        dlg.Title = "Select Crystal Reports file"
        dlg.Filter = "Crystal Reports (*.rpt)|*.rpt|All Files (*.*)|*.*"
        dlg.InitialDirectory = "C:\Program Files\Microsoft Visual Studio.NET\Crystal Reports\Samples\Reports"
        If (dlg.ShowDialog() = DialogResult().OK) Then
            Me.Cursor = Cursors.WaitCursor
            crystalReportViewer().ReportSource = dlg.FileName
            Me.Cursor = Cursors.Default
        End If
    End Sub

I want the user to select a Crystal reports using a combo box to view his report.
0
Richard Kreidl
Asked:
Richard Kreidl
  • 6
  • 5
1 Solution
 
S-TwilleyCommented:
Sub ListInCombo(ByVal RootDir As String)
   

    Dim thisDir As New IO.DirectoryInfo(RootDir)
 
    Dim thisFile as IO.FileInfo

    For Each thisFile in thisDIR.GetFiles("*.rpt")
        Combobox1.items.add(thisFile.name)
    Next

    ComboBox1.tag = RootDir
End Sub

and on the index change
    Dim fileX as string = Combobox1.SelectedItem
    fileX = combobox1.tag & fileX

============

This can be made more secure, but wasn't too sure of what you were after before i go into detail
0
 
Richard KreidlSoftware DeveloperAuthor Commented:
I tried your code and it doesn't even compile.

I get the following errors on debug:
Option Strict On disallows implicit conversions from 'System.Object' to 'String'.
Option Strict On prohibits operands of type Object for operator '&'.

0
 
S-TwilleyCommented:
sorry, did this straight into IE... I'll post up some strict code in a moment
0
Independent Software Vendors: 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!

 
S-TwilleyCommented:
try this then at least:

    Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
        If ComboBox1.SelectedItem Is Nothing Then
            'Do nothing
        Else
            Dim fileX As String = CStr(ComboBox1.SelectedValue)
            fileX = CStr(ComboBox1.Tag) & fileX
        End If
    End Sub
0
 
Richard KreidlSoftware DeveloperAuthor Commented:
It compiles now but the combo box is blank.
0
 
Richard KreidlSoftware DeveloperAuthor Commented:
This is all of the code:

Dim RootDir As String = "C:\Program Files\Microsoft Visual Studio.NET\Crystal Reports\Samples\Reports"
 Private Sub cboCrystal_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCrystal.SelectedValueChanged
        If cboCrystal.SelectedItem Is Nothing Then
            'Do nothing
        Else
            Dim fileX As String = CStr(cboCrystal.SelectedValue)
            fileX = CStr(cboCrystal.Tag) & fileX
        End If
    End Sub

Sub ListInCombo(ByVal RootDir As String)
        Dim thisDir As New IO.DirectoryInfo(RootDir)
        Dim thisFile As IO.FileInfo
        For Each thisFile In thisDir.GetFiles("*.rpt")
            cboCrystal.Items.Add(thisFile.Name)
        Next
        cboCrystal.Tag = RootDir
    End Sub
0
 
S-TwilleyCommented:
you need to call the ListInCombo sub... sorry, kinda assumed you would see that...   in your form load event or on a button:

ListInCombo("C:\Program Files\Microsoft Visual Studio.NET\Crystal Reports\Samples\Reports\")

'change the path name for whatever path holds the reports you want to load into the box
0
 
Richard KreidlSoftware DeveloperAuthor Commented:
That works but I wanted the Crystal report to open as soon as it's selected.
0
 
S-TwilleyCommented:
well i wanted to check the layout was as you liked...

Private Sub cboCrystal_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCrystal.SelectedValueChanged
        If cboCrystal.SelectedItem Is Nothing Then
            'Do nothing
        Else
            Dim fileX As String = CStr(cboCrystal.SelectedValue)
            fileX = CStr(cboCrystal.Tag) & fileX
            If IO.File.Exists(fileX) Then
                Me.Cursor = Cursors.WaitCursor
                crystalReportViewer().ReportSource = fileX
                Me.Cursor = Cursors.Default
            End IF
        End If
    End Sub
0
 
Richard KreidlSoftware DeveloperAuthor Commented:
It's still not opening the report??
0
 
S-TwilleyCommented:
put a break line on here:

If IO.File.Exists(fileX) Then

does it go into the if statement... if not, what is the value of fileX ?

if it's just the path name, try replacing:

Dim fileX As String = CStr(cboCrystal.SelectedValue)

with

Dim fileX As String = CStr(cboCrystal.SelectedItem)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now