Hello!

I'm still on my long run of selfteaching...
My current problem is this:
I have a form and I have in it three textboxes, 1 button and 1 datagridview; I also have an access database. I can retrieve the data from the dtabase and add it to the datagridview.

I'm learnig now on how to create a report without a database. But I need help on how to set the datagriview as the datasource for my report.

Thanks in advance
Leo

hI KRUXENA

this is an example similar to my code

Private Sub btSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSend.Click




        dt.Rows.Add(New Object() {"Rod", "Stephens", "Nerd"})
        dt.Rows.Add(New Object() {"Sergio", "Aragones", "Cartoonist"})
        dt.Rows.Add(New Object() {"Eoin", "Colfer", "Author"})
        dt.Rows.Add(New Object() {"Terry", "Pratchett", "?"})


    End Sub

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

        dt.Columns.Add("First Name")
        dt.Columns.Add("Last Name")
        dt.Columns.Add("Occupation")

        dgv.DataSource = dt
    End Sub

Edited 5 Years Ago by __avd: Correct [code] tags.

Private Sub btSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSend.Click




        dt.Rows.Add(New Object() {"Rod", "Stephens", "Nerd"})
        dt.Rows.Add(New Object() {"Sergio", "Aragones", "Cartoonist"})
        dt.Rows.Add(New Object() {"Eoin", "Colfer", "Author"})
        dt.Rows.Add(New Object() {"Terry", "Pratchett", "?"})


    End Sub

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

        dt.Columns.Add("First Name")
        dt.Columns.Add("Last Name")
        dt.Columns.Add("Occupation")

        dgv.DataSource = dt
    End Sub

Now I want to present this data fro dgv or datatable to crystal reports ... STuck!

Hi... What are you trying to achieve here? are you saying you want to make a report in the datagrid that is not connected to your access database?

use something like this

Dim ds As New DataSet()
        Dim dt As New DataTable
        Dim dgvrow As System.Windows.Forms.DataGridViewRow
        Dim dgvcol As System.Windows.Forms.DataGridViewColumn


        For Each dgvcol In Me.DataGridView1.Columns
            dt.Columns.Add(dgvcol.Name)
        Next

        For Each dgvrow In Me.DataGridView1.Rows
            dt.Rows.Add(dgvrow)
        Next


        Dim i As Integer = 0
        Dim j As Integer = 0

        For i = 0 To Me.DataGridView1.Rows.Count - 2
            For j = 0 To Me.DataGridView1.Columns.Count - 2
                dt.Rows(i).Item(j) = Me.DataGridView1.Rows(i).Cells(j).Value.ToString()
            Next
        Next

        ds.Tables.Add(dt)

now u have a dataset with a table same as your datagridview.. set this table as the source of your Report


hope it helps

Thanks for the answer Sandeep
But as mentioned I'm newbie here so, I would really appreciate some specification and if possible comments. specially on what should I put in Form Load and bottom click events

this is the code I did so far by miself and with others help

'the form Load
Private Sub frmStudyMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim incInv As Integer = 1
        incInv = Val(incInv) + 1


        cn = New ADODB.Connection
        cn.Open("provider = Microsoft.jet.oleDb.4.0; Data Source = Vendas.mdb")

        rs = New ADODB.Recordset
        rs.Open("SELECT * FROM ProductoE", cn, 1, 2)

        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Fixed3D
        dt.Columns.Add(New DataColumn("Serial_#", GetType(String)))
        dt.Columns.Add(New DataColumn("Descricao", GetType(String)))
        dt.Columns.Add(New DataColumn("Quantidade", GetType(Double)))
        dt.Columns.Add(New DataColumn("Preco Unitario", GetType(Double)))
        dt.Columns.Add(New DataColumn("Total", GetType(Double)))


        'dt.Columns.Add(New DataColumn("Codigo", GetType(String)))
    End Sub

'before the below code, I fetch the data from accss DB usin ADO search through SQL statements, and place the results in textboxes, and the comes the following code to take from textboxex to Datagriview through a Datatable.

Private Sub KryptonButton13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btOk.Click

        Dim sSQL As String


        cn = New ADODB.Connection
        cn.Open("provider = Microsoft.jet.oleDb.4.0; Data Source = Vendas.mdb")

        rs = New ADODB.Recordset
        sSQL = ("Select * from [ProductoE] where Bar_Code = '" & txtBarCode.Text & "'")
        rs.ActiveConnection = cn
        rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
        rs.CursorType = ADODB.CursorTypeEnum.adOpenForwardOnly
        rs.LockType = ADODB.LockTypeEnum.adLockOptimistic
        rs.Open(sSQL)
        With rs
            If Not .EOF Then
                txtProdDescrip.Text = .Fields("Descricao").Value
                txtPreco.Text = .Fields("Preco_UnitarioVenda").Value
            Else
                MsgBox("Dados Incorectos")
                clear()
                Exit Sub

            End If

        End With
        dg.DataSource = dt
        linha = dt.NewRow

        linha("Serial_#") = txtBarCode.Text
        linha("Descricao") = txtProdDescrip.Text
        linha("Quantidade") = Val("1")
        
        dt.Rows.Add(linha)
        txtBarCode.Text = ""
        txtProdDescrip.Text = ""
        txtPreco.Text = ""
        Dim total As Decimal = 0
        For Each row As DataGridViewRow In dg.Rows
            total += row.Cells("Total").Value

        Next
        lblTotalPagar.Text = Format(total, "#####0.00")

        txtBarCode.Focus()

    End Sub

Now according this can tell me or redirect me to where can I found material so I can generate my report? really appreciate your help since I'm not paying anything for it and i know that if it was to be paid, I couldnt afford it. please from depest in my heart
Thank you

Yes KRUXENA
the data is taken from DB to textboxes then added to DGV through Datatable, (dt).

thanks

This question has already been answered. Start a new discussion instead.