My Crystal Report is not showing the hole list - vb.net

Please help with my crystal report, because it doesn't show the hole list when i use parameter fields for a list. here is my class below
`Imports System.Windows.Forms.Application
Imports System.Data
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.Windows.Forms
Public Class CrystalReportHelperClass
Dim Sql As New SqlHelper
Dim CR_ParamDisVals As New ParameterDiscreteValue
Dim CR_ParamVals As New ParameterValues
Dim CR_ParamDef As ParameterFieldDefinition
Dim CR_ParamDefs As ParameterFieldDefinitions
Dim CRPTDoc As New ReportDocument
Dim CRPTViewer As New CrystalReportViewer
Public Sub New(ByRef CReport As CrystalDecisions.Windows.Forms.CrystalReportViewer)
CRPTViewer = CReport
CRPTDoc = CReport.ReportSource
End Sub
Public Sub CrystalObjectParam(ByVal CrystalReportObject As String, ByVal Message As String)
CR_ParamDisVals.Value = Message
CR_ParamDefs = CRPTDoc.DataDefinition.ParameterFields
CR_ParamDef = CR_ParamDefs.Item(CrystalReportObject)
CR_ParamVals = CR_ParamDef.CurrentValues
CR_ParamVals.Clear()
CR_ParamVals.Add(CR_ParamDisVals)
CR_ParamDef.ApplyCurrentValues(CR_ParamVals)
End Sub
Public Function GetCrystalReport() As ReportDocument
Return CRPTDoc
End Function
End Class
`
then here is the form load
Private Sub ReportEmployeeList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim RepDoc As New ReportDocument
RepDoc = CRPT_Employee.ReportSource
If Sql.HasConnection() = True Then
Dim DT As DataTable = Sql.ExecuteDataTableSP("SelectWorking")
For Each Data As DataRow In DT.Rows
CRPT.CrystalObjectParam("ID", Data(1))
Next
Else
MsgBox("System Database Cannot be Connected", MsgBoxStyle.Information)
End If
CRPT_Employee.ReportSource = CRPT.GetCrystalReport
CRPT_Employee.Refresh()
End Sub
then i have 1 parameter field in my crystal report, id -> discrete value
what should i do?
i already used other methods like this one
Private Sub SetCurrentValuesForParameterField(ByVal myParameterFields As ParameterFields, ByVal myArrayList As ArrayList)
Dim currentParameterValues As ParameterValues = New ParameterValues()
For Each submittedValue As Object In myArrayList
Dim myParameterDiscreteValue As ParameterDiscreteValue = New ParameterDiscreteValue()
myParameterDiscreteValue.Value = submittedValue.ToString()
currentParameterValues.Add(myParameterDiscreteValue)
Next
Dim myParameterField As ParameterField = myParameterFields(PARAMETER_FIELD_NAME)
myParameterField.CurrentValues = currentParameterValues
End Sub

modify your method as below if i understood what do you want>>>
Dim DT As DataTable = Sql.ExecuteDataTableSP("SelectWorking")
For Each Data As DataRow In DT.Rows
CRPT.SetParameterValue("ID", Data(1))

Related

public variables on load (vb.net)

i defined some public variables in a class, when calling some variables in another class it works sometimes and sometimes not, the below code it works for the textbox but not in the form load, what i need is to run some sql sps to retrieve some data
Imports PZ_Project.DBConnClass
Imports System.Data.SqlClient
Imports System.Data
Public Class Main
Private Sub Main_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim UserTypeID As String = DBConnClass.LogedinUserType
MainMenu.Items.Add("Hi1")
Dim UserMainMenu As New SqlCommand("User_Menu_Items_App")
UserMainMenu.CommandType = CommandType.StoredProcedure
UserMainMenu.CommandText = "User_Menu_Items_App"
UserMainMenu.Connection = Conn
Dim UserTypeParam As SqlParameter = UserMainMenu.Parameters.Add("#intUserTypeID", LogedinUserType)
Dim SQLUserTypeTableAdaptor As SqlDataAdapter = New SqlDataAdapter(UserMainMenu)
Dim SQLUserTypeDataSet As DataSet = New DataSet()
SQLUserTypeTableAdaptor.Fill(SQLUserTypeDataSet)
MessageBox.Show("1" & UserTypeID)
For i = 0 To SQLUserTypeDataSet.Tables(0).Rows.Count - 1
MessageBox.Show(SQLUserTypeDataSet.Tables(0).Rows(i).Item(0))
MainMenu.Items.Add(SQLUserTypeDataSet.Tables(0).Rows(i).Item(0).ToString)
Next
' Dim obj As Object = UserMainMenu.ExecuteScalar()
'InitializeComponent()
'Dim SelectMenuItems As String
'Dim Menu_Item As String
'Dim tsmi As New ToolStripMenuItem("Users", Nothing)
'MenuStrip1.Items.Add(tsmi)
'SelectMenuItems = "Select Distinct User_Types.Name From Users Inner Join User_Types on User_Types.ID = Users.User_Type_ID Where User_Name = '" + User_Name.Text + "'"
'ConnCommand = New SqlCommand(UserName, Conn)
'Dim SQLUserTypeTableAdaptor As SqlDataAdapter = New SqlDataAdapter(ConnCommand)
'Dim SQLUserTypeDataSet As DataSet = New DataSet()
'SQLUserTypeTableAdaptor.Fill(SQLUserTypeDataSet)
'For i = 0 To SQLUserTypeDataSet.Tables(0).Rows.Count - 1
' UserType.Items.Add(SQLUserTypeDataSet.Tables(0).Rows(i).Item(0).ToString)
'Next
'UserType.Text = UserType.Items(0).ToString
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.MouseEnter
TextBox1.Text = LogedinUserType
MessageBox.Show(LogedinUserName & " / " & LogedinUserTypeName)
End Sub
End Class
Try to change this
Dim UserTypeID As String = DBConnClass.LogedinUserType
to this
Dim DBConnClass As New DBConnClass
Add this
Dim UserTypeID As String= DBConnClass.LogedinUserType

other type of checkedlistbox need answer

i'm a new guy to learn vb...in my question to save checkedlistbox to database.
my question is:
LocalDatabase table 1: Employee
[EMPLOYEE]
Form1
LocalDatabase table 2 : record
checkedlistbox list form Employee datatable..then i want save the value to database where checkedlistbox selected...i don't know how to coding vb...can somebody help??
i have tried in code by learn in other..but still have in question in checklistbox saving.
my code
vb class
Imports System.Data.SqlClient
Public Class ConnectionDatabase
Public dset As New DataSet
Public adaptor As New SqlDataAdapter
Public conn As New SqlConnection
Public cmd As New SqlCommand
Public locate As String = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='C:\Users\asus\Documents\vs twins\TT - Copy\TT\twin.mdf';Integrated Security=True"
End class
so in vb coding is:
Imports System.Data
Imports System.Data.SqlClient
Public Class Record
Dim vs As New ConnectionDatabase
Dim tblDIV As DataTable
Dim daDIV As SqlDataAdapter
Dim dsDIV As New DataSet
Dim oCon As SqlConnection
Private Sub Record_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim oCon = New SqlConnection
oCon.ConnectionString = vs.locate
dsDIV = New DataSet
daDIV = New SqlDataAdapter("SELECT Name FROM Employee", oCon)
Dim builder As SqlCommandBuilder = New SqlCommandBuilder(daDIV)
builder.QuotePrefix = "["
builder.QuoteSuffix = "]"
Try
daDIV.FillSchema(dsDIV, SchemaType.Source, "DIV")
daDIV.Fill(dsDIV, "DIV")
tblDIV = dsDIV.Tables("DIV")
CheckedListBox1.DataSource = tblDIV
CheckedListBox1.DisplayMember = "Name"
Catch ex As Exception
MsgBox("Encountered an Error;" & vbNewLine & ex.Message)
oCon.Close()
End Try
End Sub
Private Sub CheckedListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CheckedListBox1.SelectedIndexChanged
Dim TextBox1 As Double
Dim TextBox2 As Double
Dim Ans As Double
WkH = Val(TextBox1.Text)
WkS = Val(TextBox2.Text)
Ans = WkH * WkS
Label4.Text = Ans
End Sub
that is all can be run...but i can't code in the last part (saving into database) can suggest some link or example to learn ??Please Help Thank You..

How to pass parameters to Crystal reports?

I am trying to filter customers using a parameter in Crystal, by typing a customer code in a textbox. I created a parameter for the customer code, and tried to pass it's value using the code shown below, but it is not working. When I click on the button it is showing all customers not only the filtered ones:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class ParametroCrForm
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim relatorio As New ReportDocument
relatorio.Load("C:\Users\Fernando e Flavia\Documents\Visual Studio 2010\Projects\Crystal.Estudo\Crystal.Estudo\CrystalReport1.rpt")
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue
If codigoTextBox.Text = "" Then
MessageBox.Show("Digite um c�digo de cliente", "Aten��o", MessageBoxButtons.OK, MessageBoxIcon.Stop)
Exit Sub
End If
crParameterDiscreteValue.Value = codigoTextBox.Text
crParameterFieldDefinitions = relatorio.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("codigoParametro")
crParameterValues.Clear()
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
CrystalReportViewer1.ReportSource = relatorio
CrystalReportViewer1.Refresh()
End Sub
End Class
According to explanation from ABZY, I had to add selection formula in my report.
In the link below it is explained how to do that:
http://vb.net-informations.com/crystal-report/vb.net_crystal_report_parameter_string.htm
Thanks again Abzy!!

Print Preview in vb.net is empty

Here is my code:
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Data
Imports System.Data.OleDb
Public Class Form3
Dim dgv As New DataGridView()
Dim print As New PrintDocument()
Dim preview As New PrintPreviewDialog()
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\user\Documents\Inventory\InventoryLogin\InventoryLogin\Supplies.mdb")
Try
con.Open()
Dim sql As String
sql = "SELECT * From [product info]"
Dim adapter As New OleDbDataAdapter(sql, con)
Dim dt As New DataTable("product info")
adapter.Fill(dt)
preview.PrintPreviewControl.Zoom = 1
preview.Document = print
preview.Show()
AddHandler print.PrintPage, AddressOf print_PrintPage
Catch Ex As Exception
MessageBox.Show(Ex.Message)
End Try
End Sub
Protected Sub print_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
Dim ColumnCount As Integer = dgv.ColumnCount
Dim RowCount As Integer = dgv.RowCount
Dim CellTopPos As Integer = print.PrinterSettings.DefaultPageSettings.Margins.Top
For Row = 0 To RowCount - 2
Dim CellLeftPos As Integer = print.PrinterSettings.DefaultPageSettings.Margins.Left
For Cell = 0 To ColumnCount - 1
Dim CellValue As String = dgv.Rows(Row).Cells(Cell).Value.ToString()
Dim CellWidth = dgv.Rows(Row).Cells(Cell).Size.Width + 10
Dim CellHeight = dgv.Rows(Row).Cells(Cell).Size.Height
Dim Brush As New SolidBrush(Color.Black)
e.Graphics.DrawString(CellValue, New Font("tahoma", 10), Brush, CellLeftPos, CellTopPos)
e.Graphics.DrawRectangle(Pens.Black, CellLeftPos, CellTopPos, CellWidth, CellHeight)
CellLeftPos += CellWidth
Next
CellTopPos += dgv.Rows(Row).Cells(0).Size.Height
Next
End Sub
End Class
I am trying to preview and print the items in my datagridview in vb.net
The user needs to click the "Print Preview" button to view the document before printing it, but when i click the button it just shows an empty page. How can i make the records in the datagridview appear in my preview page?
I removed the Dim dgv As New DataGridView and replaced with the name of the current DataGridView.

Empty ControlCollection at Runtime

I can't find an answer to this anywhere. I define a new instance of a forms control collection, but at runtime, the collection is empty. It works for one load button on the form, but not another. The code is exactly the same, but one works, the other doesn't. Here is the relevant code:
Private Sub miFLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miFLoad.Click
Dim FilePath As String = "C:\FList\FList.flt"
Dim LoadFile As New SaveandLoad.SaveAndLoad
Dim FileRead As New Simple3Des("MyPassword")
Dim FileString As String = FileRead.ReadFile(FilePath)
With LoadFile
.WhichList = dgFList
.FilePath = FilePath
.DecryptedString = FileRead.DecryptData(FileString)
End With
Call LoadFile.LoadFile()
End Sub
This load button not loading
Private Sub miCLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miCLoad.Click
Dim FilePath As String = "C:\FList\CList.clt"
Dim LoadFile As New SaveandLoad.SaveAndLoad
Dim FileRead As New Simple3Des("MyPassword")
Dim FileString As String = FileRead.ReadFile(FilePath)
With LoadFile
.WhichList = dgCourses
.FilePath = FilePath
.DecryptedString = FileRead.DecryptData(FileString)
End With
Call LoadFile.LoadFile()
End Sub
This one is.
Public Sub LoadFile()
Dim dgRow As DataGridViewRow
Dim dgCell As DataGridViewTextBoxCell
Dim Lines() As String = DecryptedString.Split(vbLf)
Dim LinesList As List(Of String) = Lines.ToList
LinesList.RemoveAt(Lines.Length - 1)
For Each Line As String In LinesList
Dim Fields() As String = Line.Split(",")
dgRow = New DataGridViewRow
For x = 0 To (WhichList.Columns.Count - 1) Step 1
dgCell = New DataGridViewTextBoxCell
dgCell.Value = Fields(x).ToString
dgRow.Cells.Add(dgCell)
Next
WhichList.Rows.Add(dgRow)
Next
Dim FormControls As New frmFacultyList.ControlCollection(frmFacultyList)
For Each DGV As DataGridView In FormControls
If WhichList.Name = DGV.Name Then
DGV = WhichList
DGV.Refresh()
End If
Next
End Sub
Here is where they pass the info to. Again, the FormControls variable is empty for FLoad button click, but not for CLoad button click. Any help would be appreciated.
Edit: Sorry, here are the relevant Public Properties
Public Property WhichList As New DataGridView
Public Property FilePath As String
Public Property DecryptedString As String
Public Property EncryptedString As String
Turns I solved my own problem. The Save Function wasn't writing to the file correctly, so it wasn't pulling the information correctly. Fixed.