VB.net (Dev Express XtraReport) - vb.net

Developing a VB.net Winform project with Dev ExpresDataSSols. After declaringan open SQL connection, SQL command /SqlGridAdapter, I assigned a DataTable to a Grid Control tool. The GridView from my Grid Control was passed to a Dev Express XtraReport object. The XtraReport successfully showed the DataTable from the GridControl's GridView. - I then attempted to add a Dev Express CalculatedField to my XtraReport, but the CalculatedField is not displayed in the XtraReport. Any ideas on how to correct this code? Thanks!
Dim rep As XtraReport = New XtraReport( )
rep = ReportGenerator.GenerateReport(rep, GridView1)
Dim calcField As New CalculatedField( )
rep.CalculatedFields.Add(calcField)
calcField.Data Source=rep.DataSource
calcField.DataMember=rep.DataMember
calcField.FieldType=FieldType.Int32
calcField.Name="Total"
calcField.Expression="SUM([Field])"
rep.ShowPreview()

Can you confirm that the field that you want to sum is named Field?
Are you sure to have value in the database for that field?
based on the documentation it seem ok.
sorry i can't comment because i'haven't enought reputation..

I see that you've added a calculated field to a report, but have not created a label or table cell that's bound to the calculated field. This is demonstrated in the Creating a Calculated Field (Runtime Sample) topic:
/ Bind a label's Text property to the calculated field
// depending on the report's data binding mode.
if (Settings.Default.UserDesignerOptions.DataBindingMode == DataBindingMode.Bindings)
report.FindControl("xrlabel3", true).DataBindings.Add("Text", null, "Products.myField", "{0:c2}");
else report.FindControl("xrlabel3", true).ExpressionBindings.Add(
new ExpressionBinding("BeforePrint", "Text", "FormatString('{0:c2}', [myField])"));

Related

VB stretch DataGridViewImageColumn images programmatically

What I am doing
I am developing a VisualBasic application where the GUI is separated from the data manipulation (frontend and backend). This particular piece of code keeps track of the Serial Numbers already measured and displays them in the Form as a DGV with the serial number and an image or not.
My code
In a class that the GUI Form instantiates, my data is stored in a DataTable with a BindingSource, with the second column displaying an Image when I tell it to in the program (Nothing in the beginning):
Public SerialNumbersBindingSource As New BindingSource
Public SerialNumbersDataTable As New DataTable
(...)
SerialNumbersBindingSource.DataSource = SerialNumbersDataTable
SerialNumbersDataTable.Columns.Add("Serial", Type.GetType("System.String"))
SerialNumbersDataTable.Columns.Add("Pass", MyImage.GetType)
In my GUI Form code, a DataGridView has its DataSource set to the former DataTable:
DataGridViewSerialNumber.DataSource = MyObject.SerialNumbersDataTable
By just updating the DataTable in my class, the DataGridView updates automatically to reflect the current state of it. I do it like:
SerialNumbersDataTable.Add(CurrentSerial, MyImage)
The results I get
The code works, so I can modify and access the DataTable and the DataGridView autoupdates. But the images are not stretching, so I can only see a small part of them.
What I need
I need the second column named "Pass" in DataGridView to stretch the images.
What have I tried
If I access the column, it is treated like a DGVColumn and not a DGVImageColumn, so the Layout operation fails.
DataGridViewSerialNumber.Columns("Pass").DataGridViewImageCellLayout.Stretch
Microsoft's Docs page tells me to do this, which treats the columns like DGVImageColumn as I need "Pass" to. It fails because the first column is a Text one, not image.
For Each column As DataGridViewImageColumn In DataGridViewSerialNumber.Columns("Pass")
column.ImageLayout = DataGridViewImageCellLayout.Stretch
Next
Also I have tried creating a local DGVImageColumn, modify it and write it onto the original column, but it is read-only.
Dim imageColumn As DataGridViewImageColumn
imageColumn = DataGridViewSerialNumber.Columns("Pass")
imageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch
DataGridViewSerialNumber.Columns("Pass") = imageColumn
I have also tried to do it from the designer. If I click the DGV, arrow to the right and 'Edit Column', I can create the two columns and setup Pass as ImageColumn with Stretched Layout. But when I set up DGVSerialNumbers.Datasource to my DataTable, it adds the DataTable's columns to the DGV's.
Failed DGV with columns added in designer
It's time for you to learn how to cast. If you want to access one column then don't use a loop. Simply access the column you want and then cast it as the type you want to use it as. You also need to actually assign the appropriate value to the appropriate property.
DirectCast(DataGridViewSerialNumber.Columns("Pass"), DataGridViewImageColumn).ImageLayout = DataGridViewImageCellLayout.Stretch
If you want to break that up for clarity:
Dim imageColumn = DirectCast(DataGridViewSerialNumber.Columns("Pass"), DataGridViewImageColumn)
imageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch
Also, be aware that Stretch will not retain the original aspect ratio, so you might want to use Zoom instead.

Change to dataset breaks form

WinForm, VB.Net, VS 2017
I used the dataset wizard to create a dataset. I dragged the dataset to a new form to populate a grid. I did another drag of the detail fields. The form works OK. I then edited the dataset and removed a field from the middle of the record. When I load the form no records are bound.
I added MyApplication_UnhandledException but it did not fire either.
Any clues to what might be wrong? Looks like a low-level bug to me.
I was able to reproduce the bug in VS 15.4.2
0 new Winform VB.Net
0 Add/Configure Dataset via wizard
0 add table using defaults
0 drag fields to create grid on form
0 drag fields to create detail fields
0 set as startup form
0 run - check to see navigator, grid and details function
0 edit added table - remove field using the query designer (not the first of last field - guess)
0 run - nothing works

How to load only newly added record into datagridview?

I am developing the windows application in VS 2010
I am binding the data to grid using generic collection.
Here is the code
Private sub LoadAllCustomer()
Dim oCustomerCollection as new Customers
oCustomers.LoadAll() //Loads all the collection of customers
gvCustomerGrid.DataSource = oCustomerCollection
End sub
Above code work fine...
I have details form which saved the data into customer table in DB. When I save the record , I just want to add new row into grid contains recently added record.
(Previously, I was using Devexpress's grid's RefeshDataSource property.
but now I am using Visual Studio's grid which don't have this property.)
Is there any way for it ? Or I have to load entire data into grid again to show recently added record ?

Change the Column width and Position programmatically in Crystal Reports

I want to create a report that has dynamic fields (columns). in the simpler words, there are 15 optional fields for user and the user will select 6 of them to be displayed in report.
so, for solution, I added all the columns in the report. and now I want to hide all non-selected columns and also change the width and position of the visible columns.
how can I do that in vb.net 2010 by coding?
As far as the width is concerned, you could use something like this, which will change the height and width (0 of course will hide it, so change it to a value that suits you).
Dim RptDoc As New ReportDocument
Dim _fldName As FieldObject
_fldName = RptDoc.ReportDefinition.ReportObjects("fieldObjectName")
_fldName.Width = 0
_fldName.Height = 0
About moving an object, you could try something like this:
myReport _myReport = new myReport ();
myReport .Section1.ReportObjects["myline"].Top = 10;
You need to be aware of the Section naming in your report and the correct line reference.
If you want just to visualize the data I would suggest you to use a grid. Crystal report is good for static structures. If you need to export the grid to a pdf or Excel then you can use this tool:
http://r-tag.com/Pages/BlogPost/1
Get a free license here: http://r-tag.com/Pages/CommunityEdition.aspx

Report vewier cannot add parameters

I have managed to set a dataset to my tablix on my report viewer that will hold all items belonging to a bill. The issue I present you with is I cannot seem to add any parameters to my textboxes in my .rdlc report. Is this because I have added a connection to my database? Before I added my connection I could easily add parameters, but not anymore. Take a look at my report:
All the red rectangles is where I would usually have my parameters. Is there a way to programmatically do this?
Dim rpJobNum = New ReportParameter("tbJobNo", JobNum)
rv.rvRdlc.LocalReport.SetParameters(rpJobNum)
rv is my report viewer form
rvRdlc is my report viewer control
tbJobNo is my textbox' job number name
JobNum is a variable which holds the respective value (ex: 10000)
If I execute that,I will receive an error:
Any idea why I cannot seem to add any parameter controls? Perhaps there's another way of doing this?
Figured out why I couldn't add parameters. Pretty noob stuff on my part.
Go to View > Report Data
Or... Ctrl + Alt + D
My apologies, but, I'll answer this if it can help someone!
Dim parmlist As New List(Of ReportParameter)()
parmlist.Add(New ReportParameter("tbJobNo ", JobNum))
print.ReportViewer1.LocalReport.SetParameters(parmlist)
you need to create a list, as i did here