URGENT! Adding date from Access DB into ListView

PaulieORF

Newcomer
Joined
Oct 21, 2004
Messages
24
I'm trying to add the date column from my database into a listview, but I get an error when adding the subitems. I forgot how to add the date in correctly. Here is my item adding code in form_load:

Dim mRow As DataRow
Dim mItem As ListViewItem
For Each mRow In DataSet61.Tables("Orders").Rows
'Column 1
mItem = ListView1.Items.Add(mRow.Item("Order_ID"))
'Column 2
mItem.SubItems.Add(mRow.Item("Customer_ID"))
'Column 3
mItem.SubItems.Add(mRow.Item("Date"))
'Column 4
mItem.SubItems.Add(mRow.Item("Total"))
'Column 5
mItem.SubItems.Add(mRow.Item("Fulfilled"))
Next

Plase help me, I need it working for a project that's due Monday. THANKS!
 
Joe Mamma said:
try

mItem.SubItems.Add(mRow.Item("Date").ToString())
actually do this. . .
Code:
For Each mRow In DataSet61.Tables("Orders").Rows
'Column 1
mItem = ListView1.Items.Add(mRow.Item("Order_ID"))
'Column 2
mItem.SubItems.Add(mRow.Item("Customer_ID"))
'Column 3
[b][i]new ListViewItem.ListViewSubItem(mItem,mRow.Item("Date").ToString())[/i][/b]
'Column 4
mItem.SubItems.Add(mRow.Item("Total"))
'Column 5
mItem.SubItems.Add(mRow.Item("Fulfilled"))
Next

or
Code:
For Each mRow In DataSet61.Tables("Orders").Rows
	mItem = new ListViewItem( _
		mRow.Item("Customer_ID").ToString(), _
		mRow.[i]("Date").ToString()[b],[/b] _[/i]
		mRow.Item("Total")[i].ToString(),[/i] _ 
		mRow.Item("Fulfilled")[i].ToString())[/i] 
	mItem.[i]Text = [/i]mRow.Item("Order_ID").ToString()

	ListView1.Items.Add(mItem)
Next
 
Thanks guys. Now, how can I format the date in the listview so that it does not show the time? I just want it to show up as #/#/#.
 
The date format in the database is set to short. In the Access DB it shows up as 11/22/2004, however in my listview it shows up as 11/22/2004 12:00 AM. How can I make it not show the time?

Also, I have a new question regarding ListViews. I would like to make my ListView behave like a ListBox, as in I want to be able to have the value of the item I click on be put into a string that I've dimmed, something to the effect of SelectedValue. But I noticed that ListView does not have this option. Thanks guys.
 
Back
Top