|
-
Oct 6th, 2011, 11:21 AM
#1
Thread Starter
Addicted Member
How do i populate datatable with listview
How do i populate datatable with listview. . . .i have tried this code but it doesnt give the items that contained in listview to datatable. . . .Hope someone could elp me. . . .
Code:
dt.Rows.Add(ListView1.Items("Quantity"), ListView1.Items("Description"), ListView1.Items("Price"), ListView1.Items("Total"))
-
Oct 6th, 2011, 11:46 AM
#2
Re: How do i populate datatable with listview
With a datatable, the first step is to create a new row:
Dim dr as DataRow = dt.NewRow
Then you can add the items to the row:
dr("Quantity") = ListView1.Items("Quantity")
dr("Description") = ListView1.Items("Description")
etc.
Finally, once you have put the values from the listview into the fields of the datarow where they belong, you have to add the row to the datatable:
dt.Rows.Add(dr)
That last step may seem a bit odd. Afterall, you created the datarow from the datatable, so why add it back in? Shouldn't the datatable already know about it? I don't have a good answer for that, but it is the case.
My usual boring signature: Nothing
 
-
Oct 6th, 2011, 11:49 AM
#3
Re: How do i populate datatable with listview
You may also be accessing the listview items incorrectly, unless you actually have individual rows for quantity and description. If you have rows where there are columns for quantity and description, then you are accessing them incorrectly.
-
Oct 10th, 2011, 10:12 AM
#4
Thread Starter
Addicted Member
Re: How do i populate datatable with listview
 Originally Posted by Shaggy Hiker
With a datatable, the first step is to create a new row:
Dim dr as DataRow = dt.NewRow
Then you can add the items to the row:
dr("Quantity") = ListView1.Items("Quantity")
dr("Description") = ListView1.Items("Description")
etc.
Finally, once you have put the values from the listview into the fields of the datarow where they belong, you have to add the row to the datatable:
dt.Rows.Add(dr)
That last step may seem a bit odd. Afterall, you created the datarow from the datatable, so why add it back in? Shouldn't the datatable already know about it? I don't have a good answer for that, but it is the case.
i tried your code sir but it gives me error. . . .How do i populate a datatable with my listview datas??. . . .is it possible??
-
Oct 10th, 2011, 10:28 AM
#5
Thread Starter
Addicted Member
Re: How do i populate datatable with listview
 Originally Posted by kleinma
You may also be accessing the listview items incorrectly, unless you actually have individual rows for quantity and description. If you have rows where there are columns for quantity and description, then you are accessing them incorrectly.
I have a listview columns quantity, desc, price, total etc. . . .how do i put them in the datatable all of my rows which contain the data in the listview??
-
Oct 10th, 2011, 12:19 PM
#6
Re: How do i populate datatable with listview
 Originally Posted by sukarno1234
i tried your code sir but it gives me error. . . .How do i populate a datatable with my listview datas??. . . .is it possible??
What are the errors?
If you are expecting a single method that automatically moves listview data into a datatable, such a thing does not exist. The steps will be more complicated. What I have shown is close, at the very least. If you are getting errors, tell us what they are and we can suggest a solution.
My usual boring signature: Nothing
 
-
Oct 13th, 2011, 12:15 PM
#7
Thread Starter
Addicted Member
Re: How do i populate datatable with listview
 Originally Posted by Shaggy Hiker
What are the errors?
If you are expecting a single method that automatically moves listview data into a datatable, such a thing does not exist. The steps will be more complicated. What I have shown is close, at the very least. If you are getting errors, tell us what they are and we can suggest a solution.
This is the error that it gives me. . . .
Failed to load database information.
Error in File temp_78375339-a127-43a0-9e6d-b08fdf3425aa {6FCDD6AA-CEED-4B84-B96D-C3F1A1FB6990}.rpt:
Failed to load database information.
This is my code:
Code:
Dim rpt As New crpurchase()
Dim rptForm As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim dt As New DataTable
Dim dr As DataRow = dt.NewRow
With dt
.Columns.Add("Product Name")
.Columns.Add("Quantity")
.Columns.Add("Price")
.Columns.Add("Supplier Name")
.Columns.Add("Purchase Date")
.Columns.Add("Sub Total")
End With
dr("Product Name") = lsvorder.Items("Product Name")
dr("Quantity") = lsvorder.Items("Quantity")
dr("Price") = lsvorder.Items("Price")
dr("Supplier Name") = lsvorder.Items("Supplier Name")
dr("Purchase Date") = lsvorder.Items("Purchase Date")
dr("Sub Total") = lsvorder.Items("Sub Total")
'For Each i As ListViewItem In lsvorder.Items
' dt.Rows.Add()
'Next
dt.Rows.Add(dr)
rpt.SetDataSource(dt)
frmReport.CrystalReportViewer1.ReportSource = rpt
rptForm = rpt
frmReport.Show()
-
Oct 13th, 2011, 02:39 PM
#8
Re: How do i populate datatable with listview
That error doesn't appear to deal with the datatable itself, but with something else. Which line are you getting that error on? I would guess that it is either one of the last few. There are a couple steps to take to find the problem.
1) This isn't necessarily related, but a column name with a space in it is just going to cause you trouble down the road, so turn Product Name into either ProductName or Product_Name.
2) Put a breakpoint on this line:
rpt.SetDataSource(dt)
by which time dt is fully populated, or at least as fully populated as it is going to get with that code. At that point, take a look at dt to see whether it has what you expect it to have. It should have only one row, and that row should have the items that you expect. If that all looks right, then the problem arises later (as it probably does).
My usual boring signature: Nothing
 
-
Oct 13th, 2011, 03:16 PM
#9
Thread Starter
Addicted Member
Re: How do i populate datatable with listview
This is where the error start
Code:
rpt.SetDataSource(dt)
it says that:
Failed to load database information.
Error in File temp_f44d34d7-e66c-4e1a-9951-d918ba390949 {3C61418A-CC1B-409E-BECD-D39EF79CAFE4}.rpt:
Failed to load database information.
-
Oct 13th, 2011, 03:37 PM
#10
Re: How do i populate datatable with listview
So, did you look at dt to see whether it has what you expect it to have?
I have no information about that error, as I have never worked with Crystal Reports. It sounds a bit like it is looking for schema information accompanying the datatable, which may not be available from a custom datatable such as you have, but again, I haven't worked with Crystal Reports, and can't help with that.
My usual boring signature: Nothing
 
-
Oct 13th, 2011, 03:52 PM
#11
Thread Starter
Addicted Member
Re: How do i populate datatable with listview
it doest return at all. . . .the datatable is empty i did'nt see any of my the value im listview. . . .
Code:
For Each dr As DataGridViewRow In listgrid.Rows
dt.Rows.Add(dr.Cells("Quantity").Value, dr.Cells("Description").Value, dr.Cells("Price").Value, dr.Cells("Total").Value)
Next
i use this code and it works fine but in listview is their equivalent of this code??. . . .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|