|
-
Oct 12th, 2008, 12:10 AM
#1
Thread Starter
Lively Member
[RESOLVED] [2005] Listbox Exporting And Printing Problem
My list box is getting it's data from an access database.
I try to export the contents into a txt file and I get...
System.Data.DataRowView
System.Data.DataRowView
System.Data.DataRowView
System.Data.DataRowView
System.Data.DataRowView
I get the same thing when I try to print it out.
-
Oct 12th, 2008, 01:49 AM
#2
Re: [2005] Listbox Exporting And Printing Problem
You are presumably just looping through the items and calling ToString on them. If your ListBox is bound to a DataTable then each item is a DataRowView. What you're seeing IS the result of calling ToString on a DataRowView. If what you actually want is the text displayed in the ListBox for each item then you need to loop through the item indexes and call GetItemText for each one. The documentation for the ListBox class could have told you that and that's the first place you should have looked. The documentation for the type or member you're using and having trouble with should always be the first thing you look at.
-
Oct 12th, 2008, 10:42 AM
#3
Thread Starter
Lively Member
Re: [2005] Listbox Exporting And Printing Problem
Sorry I am pretty much a noob, but I got it somewhat working, but now it exports/prints only the first entry in the list box.
I've looked for solutions but couldn't find any
Code:
Me.lstAccounts.DataSource = ds.Tables(0)
Me.lstAccounts.DisplayMember = "Username"
Me.lstAccounts.Text = Me.lstAccounts.GetItemText(Me.lstAccounts.DataSource)
-
Oct 12th, 2008, 07:03 PM
#4
Re: [2005] Listbox Exporting And Printing Problem
If you were getting multiple lines of output before you must have been using a loop. You still need to use a loop. You need to call GetItemText for each item in the control. NOT for the DataSource, for each item in the control. Take the highlight as a clue as to what sort of loop you need.
-
Oct 13th, 2008, 01:22 PM
#5
Thread Starter
Lively Member
Re: [2005] Listbox Exporting And Printing Problem
 Originally Posted by jmcilhinney
If you were getting multiple lines of output before you must have been using a loop. You still need to use a loop. You need to call GetItemText for each item in the control. NOT for the DataSource, for each item in the control. Take the highlight as a clue as to what sort of loop you need.
Thx I get what u r saying, but i tried a couple of things and i can't get the loop to work properly.
-
Oct 13th, 2008, 01:42 PM
#6
Addicted Member
Re: [2005] Listbox Exporting And Printing Problem
Hello,
If possible, could you please post what code you have so far? Someone here will be able to help you more if they see what you are trying to do versus what you are actually doing.
Basically from what I see, you have a table. ds.tables(0)
This table has rows. You need to loop through these rows, reading the data you want off of the row.
Very short example of what I'm thinking might be your root issue:
Code:
dim dt as new DataTable = ds.tables(0)
For Each dr as DataRow In dt.rows '// This is the For Each loop what JM was implying to
'//Read from the row and assign whatever you need to here
Next dr
Using Framework 2.0, VB.Net 2005.
-
Oct 13th, 2008, 01:49 PM
#7
Thread Starter
Lively Member
Re: [2005] Listbox Exporting And Printing Problem
 Originally Posted by Crushinator
Hello,
If possible, could you please post what code you have so far? Someone here will be able to help you more if they see what you are trying to do versus what you are actually doing.
Basically from what I see, you have a table. ds.tables(0)
This table has rows. You need to loop through these rows, reading the data you want off of the row.
Very short example of what I'm thinking might be your root issue:
Code:
dim dt as new DataTable = ds.tables(0)
For Each dr as DataRow In dt.rows '// This is the For Each loop what JM was implying to
'//Read from the row and assign whatever you need to here
Next dr
I just cant figure out how to loop the GetItemText Properly And What The GetItemText should be assigned to e.g Datasource
-
Oct 13th, 2008, 02:15 PM
#8
Addicted Member
Re: [2005] Listbox Exporting And Printing Problem
Oh, I thought you were trying to assign to the listview, not read from it. Sorry, that was my fault.
Hmm, could you do something like:
Code:
dim fs as new IO.FileStream("C:\", FileMode.CreateNew)
dim sw as new IO.StreamWriter(fs)
For i As Integer = 0 To (lstAccounts.Items.Count - 1)
'//Get whatever values and output however you need
sw.writeline(lstAccounts.items(i).subitems(0).text)
Next i
sw.close()
fs.close()
Not sure if something like this is what you're looking for.
Using Framework 2.0, VB.Net 2005.
-
Oct 13th, 2008, 02:28 PM
#9
Thread Starter
Lively Member
Re: [2005] Listbox Exporting And Printing Problem
http://kyrepairs.com/AM.wmv
^^
Right Click Save As
Video Explaining what is wrong and what im confused with.
-
Oct 13th, 2008, 03:39 PM
#10
Re: [2005] Listbox Exporting And Printing Problem
vb.net Code:
For Each item As Object In myListBox.Items MessageBox.Show(myListBox.GetItemText(item)) Next
As the name suggests, GetItemText gets the text for an item. What you do with that text, i.e. String object, is up to you.
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
|