vb.net crystal report view issues - vb.net

I have a vb.net application that has a list of reports that you can select from.
When you select a report it loads the data and displays the report in the Crystal Report Viewer. However, The report display is way to big and the only way to resize it is to restore down the screen and then restore it to full screen. The scroll bars are only visible after you restore the page down and up.
The generated code for the viewer is as follows.
Me.CrystalReportViewer1.ActiveViewIndex = -1
Me.CrystalReportViewer1.AutoValidate = System.Windows.Forms.AutoValidate.EnablePreventFocusChange
Me.CrystalReportViewer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.CrystalReportViewer1.Cursor = System.Windows.Forms.Cursors.Arrow
Me.CrystalReportViewer1.DisplayBackgroundEdge = False
Me.CrystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill
Me.CrystalReportViewer1.EnableDrillDown = False
Me.CrystalReportViewer1.Location = New System.Drawing.Point(230, 0)
Me.CrystalReportViewer1.Name = "CrystalReportViewer1"
Me.CrystalReportViewer1.SelectionFormula = ""
Me.CrystalReportViewer1.ShowCloseButton = False
Me.CrystalReportViewer1.ShowGroupTreeButton = False
Me.CrystalReportViewer1.ShowRefreshButton = False
Me.CrystalReportViewer1.ShowTextSearchButton = False
Me.CrystalReportViewer1.Size = New System.Drawing.Size(517, 715)
Me.CrystalReportViewer1.TabIndex = 1
Me.CrystalReportViewer1.ToolPanelView = CrystalDecisions.Windows.Forms.ToolPanelViewType.None
Me.CrystalReportViewer1.ViewTimeSelectionFormula = ""
I am calling it like this:
Dim rpt As String
rpt = ListBox1.Items(ListBox1.SelectedIndex)
If Not CrystalReportViewer1.ReportSource Is Nothing Then CrystalReportViewer1.ReportSource.dispose()
Select Case rpt
Case "Scoot"
myreport = New graduation
LoadDatabaseInfo(myreport)
myreport.SetParameterValue("doop", indrno.Text)
'myreport.SetParameterValue("dte", indate.Value)
myreport.SetParameterValue("name", txb.Text)
CrystalReportViewer1.ReportSource = myreport
CrystalReportViewer1.Refresh()
CrystalReportViewer1.Zoom(55)
How do I fix This.. Thank you so much

Rather than zooming to 55 percent, try using a value of 1 to fit to the width of the page or 2 to fit in the page (from MSDN).

I was able to accomplish my resizing needs by setting the height and width properties of the window to set pixel values.
i.e.
CrystalReportViewer.Width = 1100
CrystalReportViewer.Height = 1200
It takes some playing around to get your values correct but this worked and I didn't have any zooming issues.

Related

Dropdown property setting for a Comboboxcol in datagridview in vb.net

I am facing a problem in VB.Net Winforms Application. I am using VS 2019.
The problem is the combobox column in Datagridview is not dropping down to show the list.
mDT and mDT1 are DataTables
ShowData is the name of the Datagridview
The properties in the designer for Show Data is shown below ( partially )
I tried various suggestions given in MSDN as well as here but am not successful. Might be because those might be old or are implemented differently in VS 2019.
The properties in the designer for Show Data is shown below ( partially )
[DGV Properties](https://i.stack.imgur.com/h60oO.jpg)
The Code
Dim mRow As DataRow
mDT = gDT_Structures.Copy()
mDT1 = New DataTable
mDT1.Columns.Add("PFID")
mDT1.AcceptChanges()
mRow = mDT1.NewRow()
mRow("PFID") = "PFID01"
mDT1.Rows.Add(mRow)
mDT1.AcceptChanges()
mRow = mDT1.NewRow()
mRow("PFID") = "PFID02"
mDT1.Rows.Add(mRow)
mDT1.AcceptChanges()
ShowData.Visible = True
ShowData.DataSource = mDT
'//Combobox column.
Dim ComboBoxcol = New DataGridViewComboBoxColumn()
ComboBoxcol.DataSource = mDT1
ComboBoxcol.Name = "PFID"
ComboBoxcol.ValueMember = "PFID"
ComboBoxcol.DisplayMember = "PFID"
ShowData.Columns.Add(ComboBoxcol)
For i = 0 To ShowData.Columns.Count() - 1
ShowData.Columns(i).ReadOnly = False
Next
ShowData.Select()
ShowData.Show()
The results View
[DGV Result](https://i.stack.imgur.com/l1Wi1.jpg)
Request guidance.
Thanks in Advance.

Data grid view with combo box , add rows from data table

Search and display data in data grid view
Dim cmd As New OracleCommand("Select JV_CODE,JV_ACC_NAME,DEBIT,CREDIT From VOUCHER_DETAIL where VOUCHERNO =:Vno", sgcnn)
cmd.Parameters.Add("#Vno", OracleDbType.NVarchar2).Value = txtJVNo.Text.ToString.Trim
Dim daVD As New OracleDataAdapter(cmd)
Dim dtVD As New DataTable()
daVD.Fill(dtVD)
dgvAccDetail.AutoGenerateColumns = False
dgvAccDetail.DataSource = dtVD
dgvAccDetail.Rows(0).Cells(0).Value = dtVD.Rows(0).Item("JV_CODE").ToString.Trim
dgvAccDetail.Rows(0).Cells(1).Value = dtVD.Rows(0).Item("JV_ACC_NAME").ToString.Trim
dgvAccDetail.Rows(0).Cells(2).Value = dtVD.Rows(0).Item("DEBIT").ToString.Trim
dgvAccDetail.Rows(0).Cells(3).Value = dtVD.Rows(0).Item("CREDIT").ToString.Trim
Catch ex As Exception
MsgBox(ex.Message)
End Try
There are two rows in dtVD data table but result shows only one I stack with this some can tell what I'm doing wrong ?
The reason for this is that you are only assigning the one row. You have a couple options:
First, this code below here shouldn't really be necessary, of you setup the property binding on the grid. You'll get better performance that way if you use a bind. You don't have your GUI code here, but essentially your DataPropertyName field on the columns should be set.
dgvAccDetail.Rows(0).Cells(0).Value = dtVD.Rows(0).Item("JV_CODE").ToString.Trim
dgvAccDetail.Rows(0).Cells(1).Value = dtVD.Rows(0).Item("JV_ACC_NAME").ToString.Trim
dgvAccDetail.Rows(0).Cells(2).Value = dtVD.Rows(0).Item("DEBIT").ToString.Trim
dgvAccDetail.Rows(0).Cells(3).Value = dtVD.Rows(0).Item("CREDIT").ToString.Trim
If you insist on manually assigning the cell values, you cannot just do row 0 (that's the first row). You need to do all the rows in a loop.
For i as Integer = 0 to dtVD.Rows.Count - 1
dgvAccDetail.Rows(i).Cells(0).Value = dtVD.Rows(i).Item("JV_CODE").ToString.Trim
dgvAccDetail.Rows(i).Cells(1).Value = dtVD.Rows(i).Item("JV_ACC_NAME").ToString.Trim
dgvAccDetail.Rows(i).Cells(2).Value = dtVD.Rows(i).Item("DEBIT").ToString.Trim
dgvAccDetail.Rows(i).Cells(3).Value = dtVD.Rows(i).Item("CREDIT").ToString.Trim
Next

How do I collapse white space in a list of string that was randomized

I have a list of strings that hold 10 answers.
Each question has a different amount of answers 2-10.
After randomizing the list, I end up with white space or empty spaces in my list depending on the number of answers.
After randomizing the list of let's say 2 answers, i would like to shift them back to position 0 and 1 in my list keeping the size of the list at 10 and of course keeping the order randomized.
I'm not sure how to programmatically solve this problem...
I've tried to sort/reverse the list after randomize, but of course, this removes the randomization.
I've tried to remove the white space with something like
answerlist.RemoveAll(Function(str) String.IsNullOrWhiteSpace(str))
but I then get an out of bounds when trying to write them back to my radiobuttons.text as there are 10 of them.
This is where writing my list of...
RadioAnswer1.Text = answerlist(0)
RadioAnswer2.Text = answerlist(1)
RadioAnswer3.Text = answerlist(2)
RadioAnswer4.Text = answerlist(3)
RadioAnswer5.Text = answerlist(4)
RadioAnswer6.Text = answerlist(5)
RadioAnswer7.Text = answerlist(6)
RadioAnswer8.Text = answerlist(7)
RadioAnswer9.Text = answerlist(8)
RadioAnswer10.Text = answerlist(9)
Ideally, I want the list randomized then however many answers there are written back into the list starting at 0 going down to 10.
I hope my question is clear.
Additional info edit
So here is how I'm loading the answers into the List Of..
Dim answerlist As New List(Of String)
WEFESQLConn.ConnectionString = connectstring
WEFESQLConn.Open()
WERESQLStatment.CommandText = "SELECT * FROM [WEFE Questions] WHERE QuestionID = " & SQLQuestionNum.ToString
WERESQLStatment.Connection = WEFESQLConn
WEFESQLRead = WERESQLStatment.ExecuteReader
If WEFESQLRead.HasRows Then
WEFESQLRead.Read()
lblQuestion.Text = WEFESQLRead.Item("Question").ToString
answerlist.Add(WEFESQLRead.Item("CorrectAnswer").ToString)
answerlist.Add(WEFESQLRead.Item("Answer2").ToString)
answerlist.Add(WEFESQLRead.Item("Answer3").ToString)
answerlist.Add(WEFESQLRead.Item("Answer4").ToString)
answerlist.Add(WEFESQLRead.Item("Answer5").ToString)
answerlist.Add(WEFESQLRead.Item("Answer6").ToString)
answerlist.Add(WEFESQLRead.Item("Answer7").ToString)
answerlist.Add(WEFESQLRead.Item("Answer8").ToString)
answerlist.Add(WEFESQLRead.Item("Answer9").ToString)
answerlist.Add(WEFESQLRead.Item("Answer10").ToString)
answerlist.RemoveAll(Function(str) String.IsNullOrWhiteSpace(str))
WEFESQLRead.Close()
WEFESQLConn.Close()
RadioAnswer1.Text = answerlist(0)
RadioAnswer2.Text = answerlist(1)
RadioAnswer3.Text = answerlist(2)
RadioAnswer4.Text = answerlist(3)
RadioAnswer5.Text = answerlist(4)
RadioAnswer6.Text = answerlist(5)
RadioAnswer7.Text = answerlist(6)
RadioAnswer8.Text = answerlist(7)
RadioAnswer9.Text = answerlist(8)
RadioAnswer10.Text = answerlist(9)
With this code I get the out of bounds as there are not enough answers to populate the answerlist.
Without
answerlist.RemoveAll(Function(str) String.IsNullOrWhiteSpace(str))
I get the spaces in my pre-drawn radio buttons.
I am all ready hiding the unused buttons - the issue there are 10 positions for the buttons and with the randomization of the list.
4 spots of 10 used image
Why don't you toggle the visibility of the controls dynamically after removing the blank entries from the list? Take a look at this example:
'Store all controls in a collection
Dim answers(9) As RadioButton = {RadioAnswer1, RadioAnswer2, RadioAnswer3, RadioAnswer4, RadioAnswer5, RadioAnswer6, RadioAnswer7, RadioAnswer8, RadioAnswer9, RadioAnswer10}
'Iterate through all answers
For index As Integer = 0 To answerlist.Count - 1
'Show the control and set the text
With answers(index)
.Text = answerlist.Item(index)
.Visible = True
End With
Next
'Loop through the rest of the answer controls
For index As Integer = answerlist.Count To answers.Length - 1
'Hide the control
answers(index).Visible = False
Next
Initial setup...
Dim radioButtons As New List(Of RadioButton)
radioButtons.Add(RadioAnswer1)
radioButtons.Add(RadioAnswer2)
...
radioButtons.Add(RadioAnswer10)
After removing blank answers from the randomized list...
For i = 0 To answerList.Count - 1
radioButtons(i).Text = answerList(i)
radioButtons(i).Visible = True
Next
For i = answerList.Count to radioButtons.Count - 1
radioButtons(i).Visible = False
Next
To close this out I ended up going with removing all the spaces from my ListOF then using a DO WHILE for each radiobutton.text entries.
example portion
answerlist = RandomizeListOrder(answerlist)
answerlist.RemoveAll(Function(str) String.IsNullOrWhiteSpace(str))
Dim ALCount As Integer = answerlist.Count
Dim ALCounter = 0
Do
If ALCounter < ALCount Then
ALCounter += 1
RadioAnswer1.Text = answerlist(0)
ElseIf ALCounter = ALCount Then
Exit Do
End If
Maybe not very clean as there are 10 of these entries, but I'll work on that later. Just trying to get the idea out.
Thanks everyone for the suggestions they got me on the right path.

Retrieving an item from a list based on selected value

The function retrieveFixtureReport() returns a list of Report, each of which contains a PlayerID. I'm trying to set my labels to reflect the selected Report chosen from cmbSelectedPlayer. Each Report within the list contains a unique PlayerID. I've tried a variety of different ways to access the properties of the selected Report, including LINQ, but have been unsuccessful so far. A For Each loop doesn't seem to be the right option to select just one Report, it also prevents me from selecting other PlayerID's from cmbSelectedPlayer (only the last Report in the list is shown). The code is shown below:
Public Sub setFixtureReport()
'If UC_Menu_Scout1.cmbSelectedPlayer.SelectedItem IsNot Nothing Then
If UC_Menu_Scout1.cmbSelectedPlayer.Items.Count > 0 Then
Dim getPlayerReport = _
(From rpt As Report In retrieveFixtureReport() _
Where rpt.PlayerID = UC_Menu_Scout1.cmbSelectedPlayer.SelectedItem.PlayerID) '.AsEnumerable
'For Each rpt As Report In getPlayerReport()
'For Each rpt As Report In retrieveFixtureReport.Where(Function(x) x.PlayerID = UC_Menu_Scout1.cmbSelectedPlayer.SelectedItem.PlayerID)
'Dim rpt As Report = getPlayerReport 'retrieveFixtureReport(0)
'*****General Information
UC_Menu_Scout1.lblRptPosition.Text = rpt.PositionPlayed
UC_Menu_Scout1.lblFoot.Text = rpt.PreferredFoot
UC_Menu_Scout1.txtComments.Text = rpt.Comments
UC_Menu_Scout1.lblStatus.Text = rpt.MonitorStatus
'Next
setColours()
'End If
End If
End Sub
The combobox cmbSelectedPlayer is filled from playerList (this is added to in retrieveFixxtureReport as well):
UC_Menu_Scout1.cmbSelectedPlayer.DataSource = playerList
UC_Menu_Scout1.cmbSelectedPlayer.DisplayMember = "PlayerFullName"
UC_Menu_Scout1.cmbSelectedPlayer.ValueMember = "PlayerID"
Any suggestions would be appreciated.
If your combobox was bound to a List(Of Player) then all you would need to do is cast the SelectedItem to it's type:
Dim player = TryCast(UC_Menu_Scout1.cmbSelectedPlayer.SelectedItem, Player)
If Not player Is Nothing Then
Dim getPlayerReport = (From rpt As Report In retrieveFixtureReport()
Where rpt.PlayerID = player.PlayerID).FirstOrDefault()
If Not getPlayerReport Is Nothing Then
UC_Menu_Scout1.lblRptPosition.Text = getPlayerReport.PositionPlayed
UC_Menu_Scout1.lblFoot.Text = getPlayerReport.PreferredFoot
UC_Menu_Scout1.txtComments.Text = getPlayerReport.Comments
UC_Menu_Scout1.lblStatus.Text = getPlayerReport.MonitorStatus
End If
End If

ASPxGridViewExporter does not export the data

i have dev express ASPxGridView. the column and data for the gridview will be dynamically based on the dropdown value.
If type = "procedure" Then
SqlDataSource2.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
Else
SqlDataSource2.SelectCommandType = SqlDataSourceCommandType.Text
End If
SqlDataSource2.SelectCommand = rptquery
Try
SqlDataSource2.DataBind()
dataview1 = SqlDataSource2.Select(System.Web.UI.DataSourceSelectArguments.Empty)
gv.DataSourceID = "SqlDataSource2"
For Each dc In dataview1.Table.Columns
Dim DynamicColumn = New DevExpress.Web.ASPxGridView.GridViewDataTextColumn()
DynamicColumn.FieldName = dc.ColumnName
DynamicColumn.Caption = dc.ColumnName
gv.Columns.Insert(i, DynamicColumn)
i = i + 1
Next
gv.DataBind()
Catch ex As Exception
End Try
Then i have export button to excel. my problem is it will only export the column name of the gridview into the excel sheey. data is empty. but in gridview data is shown.
please help me on this issue.
Make sure that you have bound ASPxGridView prior using the using the ASPxGridViewExporter.Write*** method:
'SqlDataSource2.DataBind()
'dataview1 = SqlDataSource2.Select(System.Web.UI.DataSourceSelectArguments.Empty)
ASPxGridViewExporterInstance.GridView = gv
gv.DataSource = SqlDataSource2
ASPxGridViewExporterInstance.Write***