Results 1 to 4 of 4

Thread: [RESOLVED] Report and textbox.

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2006
    Location
    TNQ
    Posts
    40

    Resolved [RESOLVED] Report and textbox.

    First post so be gentle please. I will probably have a pile more. But a question or two for you lot.

    I have a windows application in vb.net that is basically an addressbook. To navigate the contents I have a treeview which, when clicked on the nodes, populates a few textboxes (firstname, surname, zip etc). I want to be able to have a report print depending on which node (record) is chosen. So...questions...

    Can I populate a report from a Treeview control? (I'm using reportviewer) Reportviewer works well but has ALL data displayed. How can I filter data from a textbox (say txtFirstName) on my form? Hardcoding a firstname filter gives the correct record but I want it dynamic.

    If I can't populate from treeview, can I populate my report depending on what is in the textboxes on the form?

    Thanks for any pointers and I look forward to being part of this community.

  2. #2
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Re: Report and textbox.

    Welcome On The Forums
    You are able to get the report using the tree view, when you are clicking on the tree view then just got the primary key to the related record.
    The using the SQL query you are able to get the different report for the different nodes.
    But there is a necessary primary key is needed.
    For getting the more detail about the CR in the VB.NET just click on the link at my signature CR in VB.Net

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2006
    Location
    TNQ
    Posts
    40

    Re: Report and textbox.

    Thanks for the welcome. I may have been misleading. I cannot populate the report from treeview. I have to make a new dataset and populate it from that. My primary key is 'surname'. Here is the code.

    Code:
    Public Class Form1
        Inherits System.Windows.Forms.Form
    
        Private Const APP_TITLE = "ContactsTreeView"
    
        ' The <New> node.
        Private m_NewNode As TreeNode
    
        ' The CurrencyManager synchronizes the controls 
        ' with the Contacts DataTable.
        Private WithEvents m_CurrencyManager As CurrencyManager
    
        ' Fill the DataSet.
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ' Load the cboState ComboBox.
            Dim states() As String = { _
                "AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", _
                "GA", "HI", "IA", "ID", "IL", "IN", "KS", "KT", "LA", "MA", _
                "MD", "ME", "MI", "MN", "MO", "MS", "MT", "NC", "ND", "NE", _
                "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PE", "RI", _
                "SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA", "WI", "WV", _
                "WY" _
            }
            cboState.Items.Clear()
            cboState.Items.AddRange(states)
    
            ' Hide the txtSnapshotFile control.
            ' If we do this at design time, 
            ' it doesn't get updated by the DataSet.
            txtSnapshotFile.Visible = False
    
            ' Make the name list as large as possible.
            ArrangeControls()
    
            ' Fill the DataSet.
            daContacts.Fill(dsContacts)
    
            ' Load the TreeView.
            LoadTreeView()
    
            ' Save a reference to the CurrencyManager.
            m_CurrencyManager = Me.BindingContext(dsContacts, "Contacts")
        End Sub
    
        ' Load the TreeView control with a list of names.
        Private Sub LoadTreeView()
            Dim letter_nodes(25) As TreeNode
            Dim letter As Integer
            Dim row_num As Integer
            Dim data_row As DataRow
            Dim record_node As TreeNode
            Dim first_node As TreeNode
            Dim combined_name As String
    
            ' Make the letter nodes.
            trvContacts.Nodes.Clear()
            For letter = 0 To 25
                letter_nodes(letter) = trvContacts.Nodes.Add(Chr(letter + Asc("A"c)))
            Next letter
    
            ' Add a TreeNode column to the table.
            dsContacts.Tables("Contacts").Columns.Add("TreeNode", GetType(TreeNode))
    
            ' Add each name entry.
            For row_num = 0 To dsContacts.Tables("Contacts").Rows.Count - 1
                data_row = dsContacts.Tables("Contacts").Rows(row_num)
                combined_name = data_row.Item("LastName") & ", " & data_row.Item("FirstName")
                letter = Asc(combined_name.Substring(0, 1).ToUpper) - Asc("A"c)
                record_node = letter_nodes(letter).Nodes.Add(combined_name)
                record_node.Tag = data_row
                data_row.Item("TreeNode") = record_node
                If row_num = 0 Then first_node = record_node
            Next row_num
    
            ' Make a <New> node.
            m_NewNode = trvContacts.Nodes.Add("<New>")
    
            ' Select the first node.
            trvContacts.SelectedNode = first_node
    
            ' Accept the changes (setting the TreeNode field) 
            ' so we don't think there are changes yet.
            dsContacts.AcceptChanges()
        End Sub
    
        ' Make the TreeView as large as possible.
        Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
            ArrangeControls()
        End Sub
        Private Sub ArrangeControls()
            trvContacts.SetBounds(0, 0, trvContacts.Size.Width, ClientSize.Height)
        End Sub
    
        Private Sub mnuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileExit.Click
            Me.Close()
        End Sub
    
        Private Sub trvContacts_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles trvContacts.AfterSelect
            Dim data_row As DataRow
            Dim data_table As DataTable
            Dim i As Integer
    
            ' Do nothing if we haven't loaded the data yet.
            If m_CurrencyManager Is Nothing Then Exit Sub
    
            ' Do nothing if this node has no Tag 
            ' value or Tag isn't a DataRow object.
            If e.Node.Tag Is Nothing Then Exit Sub
    
            ' Display the corresponding record.
            data_table = dsContacts.Tables(0)
            data_row = e.Node.Tag
            For i = 0 To m_CurrencyManager.Count - 1
                If data_row Is m_CurrencyManager.List(i).Row Then
                    m_CurrencyManager.Position = i
                    Exit For
                End If
            Next i
        End Sub
    End Class
    This was a tutorial I followed. I want to add a report but cannot see where to take the string from to populate the report.

    Thanks for any help.

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2006
    Location
    TNQ
    Posts
    40

    Resolved Re: Report and textbox.

    OK here's how I sorted it. Made another table in the database called report. Made the report table update with the textboxes text from the form when the treeview is clicked. I created a dataset that populated my report from the table 'report'. That may be a long way round but it works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width