How to get new Data Source value in Data source dropdown in SQL Report Viewer Designer 2010 - reportviewer

I am using Visual Studio 2010 with the ReportViewer Control 2010.
I create a new report and choose New -> DataSet
From the Data source: dropdown I see a list of namespaces and methods available for reporting against collections.
How do I get additional objects into this list as it seems to almost be semi random about what is shown in there?
Basically, I have referenced the DLL that contains my enumerable object as the source for reporting but it is not showing up in the Data source drop down.

I noticed the dataset does not appear if the source is exposed as a Property and not a method.
ie this fails to be a selectable data source.
public class FooData
{
public List<string> Data {get;set;}
}
but this will show up as a data source
public class FooData
{
public List<string> GetData();
}

Related

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 ?

How to specify a data object for a WinForms datagridview in code?

I created a class with public properties and added it as a new DataSource object in a WinForms project.
Public Class ICS211DetailCols
Public Property ID As Integer
Public Property fk211 As Integer
Public Property StateAbbreviation As String
...
End Class
When I add a DataGridView control to a Form from the ToolBox, the DataSource property can be set to the BindingSource created by the DataSource object (ex. ICS211DetailColumnsBindingSource) by selecting it from the Other Data Source ComboBox and all columns will appear in the DataGridView Columns collection.
I would now like to create a DataGridView in code and associate the same BindingSource but cannot seem to find any information on how this is accomplished. Is this even possible to do in code, or must I add the columns to the collection individually?

Using list of custom Class object as data source for crystal report

I am trying to find way to design a report using my own custom class.
I found links:
1.) How to work in Crystal Report with Object Data Source?
2.) Use .net object as data source in Crystal Report 2008
3.) Binding object with List<> to Crystal Report
4.) How to assign Custom class as datasource in crystal report
They were quite helpful, but I have been stuck in the first step while designing report as my custom class's property is not listed in field list of crystal report design view.
Sample of my Custom Class:
class UserType
public property UIN as integer...
public property Title as string...
end class
class User
public property UIN as Integer...
public property Name as string...
public property Password as String...
public property Type as UserType...
end class
When I add my class objects to crystal report I do not get the usertype field from users class in field list.
So how can I add usertype field to my field list? Or do I have to take another approach?
Edit:
The reason i wanted to use it as i am:
1.) Showing a form where user can type keyword
2.) program filters the records as per keyword using LINQ
3.) when user clicks the print button, I want to set the filtered records as datasource of my report
Create your dataset with the columns matching your class, and assign
the dataset to your report normally.
When you have your object class loaded with data, and/or filtered with values entered by users (filtered with linq etc..)
do this:
dim yourDataset as dataset ' this is your typed dataset
Dim dr As datarow
For n As Integer = 0 To yourClass.Count - 1
dr = yourDataset.tables("TableName").NewRow
dr("ColumnNameOne") = yourClass(n).PropertyName
dr("ColumnNameTwo") = yourClass(n).PropertyName
yourDataset.tables("TableName").Rows.Add(dr)
Next
' bind the datasource
crystalreport.SetDatasource(ds)
You could try serializing the object to XML, supply an XSD, then use Crystal Report's XML driver to connect to it. The report will 'see' the object as two tables: one for the User and one for UserType. You'll include both 'tables' in the report and link the tables using the internal_id field.
Why don't you assign a strongly typed dataset to your report and save yourself lots of trouble?

creating a drill through rdlc report in vb.net in Visual studio 2010

I have a parent and child report that I created in visual studio 2010 using winforms in vb.net. I have setup one text box in the parent report to go to the child report with the respective value as the paramter. However, when I click on the link I get the error:
a data source instance has not been supplied for the data source 'dataset1'
I realize that the dataset1 has to be filled, however I cannot figure out how to fill dataset1. I have researched the topic cand came with the following links:
http://www.developerfusion.com/t/vb.net/
http://msdn.microsoft.com/en-us/library/microsoft.reporting.winforms.reportviewer.drillthrough.aspx
On the winform where the reportviewer controller is located, I have the report drill through handler, but I do not understand how to set the dataset.
I have the following, and I am stuck on how to move on:
Private Sub ReportViewer1_Drillthrough(ByVal sender As System.Object, ByVal e As Microsoft.Reporting.WinForms.DrillthroughEventArgs) Handles ReportViewer1.Drillthrough
Dim localreport = e.Report
Me.Sp_get_testaccountsTableAdapter1.Fill(Me.Retreival.sp_get_testaccounts)
Dim od As New RetreivalTableAdapters.sp_get_testaccountsTableAdapter
End Sub
As you can see, I am filling the table adapter that dataset 1 is supposed to be connected to, but the dataset1 is still not filling... Please help!
Do I need to set a new sqlconnection?? Why do I need to do this? Why can I not just use the sqlconnection string that my tableadapter is using??
Thank you for your help!!
Based upon the example you provided (the second link), the code for accomplishing what you want to do is as follows:
void DemoDrillthroughEventHandler(object sender,
DrillthroughEventArgs e)
{
LocalReport localReport = (LocalReport)e.Report;
localReport.DataSources.Add(new ReportDataSource("Employees",
LoadEmployeesData()));
}
This shows how to assign a new DataSource based upon the drill-through functionality. Just follow the example on the website you gave and you will be fine.
As for why you need to do it, you have to load new data based upon the user drilling into your data.
Your question about filling the table adapter that the dataset is connected to seems a bit confusing. A dataset holds a set of tables. The DataSource for your report uses one table out of a dataset. Therefore, it looks like you might be trying to work backwards (filling a table to fill a dataset).

How to serialize and deserialize a form?

How do I serialize and deserialize my main form (and its controls, subcontrols, their values, etc.)?
Edit, for clarification. Currently I am writing the current value of each control to an .INI file, one by one and reading it back when the program is next run. Every time I add a new control, I have to remember to update that save/load .INI code.
I just wondered if I can do it in one call, or a simple for loop iterating over all controls on the form.
Btw, I use only simple controls like edit box, radio button, combo box, checkd listbox, the most complex thing I have is a datagrid, but even that is not linked to a databse.
Accepted answer "can't. I will probably code my own, along the lines of ...
for each child control (recursivley)
if conrol is editbox ...
if control is radiobutton ...
if ... etc
write control name to .ini file
write control "value" to .ini file
maybe later add left/top/height/width/enabled/visible, etc, bu tfor not th econtrol name an its "value" are enough (text, value, lines, checked?, etc)
There's no out-of-the-box support for serializing .NET forms and controls. Controls are not marked with the [Serializable] attribute.
I think most of the difficulty revolves around .NET controls that are really wrappers of native Win32 controls. Persisting the native state as XML, it seems, would be infeasible.
Perhaps someone has written a custom serializer; if not, you may need to roll your own.
Edit:
I found this discouraging accepted answer on experts exchange:
You have to implement ISerializable
or IXmlSerializable in order to do
something like that (depending on how
do you want to serialize the form).
It's not trivial.
Serializing the entire control sounds like a difficult proposition. However, if you want to serialize the data within that control, that's certainly possible, assuming you have it structured decently well.
For example, let's say you have a Person object with a List of Address for your AddressBook application:
Public Class Person
Public Property PersonName As String
Public Property PersonAge As Integer
Public Property Addresses As New List(Of Address)()
End Class
Public Class Address
Public Property StreetAddress As String
Public Property City As String
Public Property State As String
Public Property Zip As String
End Class
If you bind this data to your form, you can easily serialize and deserialize it to and from XML. To serialize:
Imports System.Xml.Serialization '<==you need to import this namespace '
'...'
Dim thisPerson As New Person()
Dim serializer = new XmlSerializer(thisPerson.GetType())
Using writer = XmlWriter.Create("thisPerson.xml"))
serializer.Serialize(writer, thisPerson)
End Using
To deserialize:
Dim thisPerson As New Person()
Dim serializer As New XmlSerializer(thisPerson.GetType())
Using reader = XmlReader.Create("thisPerson.xml")
thisPerson = CType(serializer.Deserialize(reader),Person)
End Using
I learned about XML Serialization from this answer to a question I had previously asked.
Granted, if you're manually loading/extracting data from your forms, this isn't going to work. I good idea might be to encapusate your underlying data for a form in a class and then bind that class to the form. This way, you can easily serialize/deserialize the data in the form.