What I'm trying to do in a listview is calculate the time now from a time in the table and place that result into a column on the grid for each record.
I was able to do this great using a datagrid, I'm exploring into the listview world and I cant seem to figure out how to do this...here is my code - Function fncDaysOpen()
-
-
Dim row As Integer
-
Try
-
For row = 0 To Mydataset3.Tables(0).Rows.Count - 1
-
-
'Convert DateTime String
-
Dim order_date As String
-
order_date = lstGrid.Items(row).SubItems(2).Text
-
Dim conv As DateTime
-
conv = System.Convert.ToDateTime(order_date)
-
-
Dim d1 As DateTime = conv
-
Dim d2 As DateTime = System.DateTime.Today
-
-
Dim subtract, absday
-
subtract = 0
-
Select Case DatePart("w", d1)
-
Case 1
-
subtract = subtract + 1
-
Case 7
-
subtract = subtract + 2
-
End Select
-
-
Select Case DatePart("w", d2)
-
Case 1
-
subtract = subtract + 2
-
Case 7
-
subtract = subtract + 1
-
End Select
-
absday = DateDiff("d", d1, d2) - 1
-
-
fncDaysOpen = absday - CInt(2 * (absday \ 7))
-
-
'I get My Error Right Here - when placing results for each rec.
-
-
lstGrid.Items(row).SubItems(7).Text = fncDaysOpen
-
-
Next row
-
Catch ex As Exception
-
MsgBox(ex.Message)
-
End Try
-
End Function<b></b>
Thanks for any help
6 1957
First off, why are you doing all that date part work?
DateTime objects can be subtracted from eachother -
dim t as TimeSpan
-
t= (TimeSpan)(DateTime.Now-saveddatetime)
-
dim numdays as Double
-
numdays=t.TotalDays
-
-
'now you have a double with the total number of whole(and fractional!) days inbetween the two dates. Feel free to round off as you wish.
-
Secondly,
Does your listgrid have as many rows as your dataset already? Do they have a 7th subitem?
First off, why are you doing all that date part work?
DateTime objects can be subtracted from eachother -
dim t as TimeSpan
-
t= (TimeSpan)(DateTime.Now-saveddatetime)
-
dim numdays as Double
-
numdays=t.TotalDays
-
-
'now you have a double with the total number of whole(and fractional!) days inbetween the two dates. Feel free to round off as you wish.
-
Secondly,
Does your listgrid have as many rows as your dataset already? Do they have a 7th subitem?
Thanks for that Code Snippet I'll give that a shot...
Yes grid has as many rows as my dataset. Rows 0 - 6 is coming from the database - row 7 is what I created to store the calculations of Date.Now - row 2.
Thanks for the help and the suggestion.
ahh, if your listview is bound to a datasource, you cannot add columns/rows to it. What you can do as an easy workaround, is in your SQL query, get another column that you can use as scratch.
So if you have "SELECT * FROM MYTABLE" you would say "SELECT *, myIDColumn as [Computed Column] FROM MYTABLE"
And then you would have an extra column called "Computed Column" that you can over-write the data in to be your computed value.
OHHHH.....I'll give that a shot...Question? how would I do this if I have to create two columns - syntax?? - "Select * myIDcolumn as [Computed Column_one], [Computed Column_two] Frm Mytable"
I'll definetly give this a shot. Thanks for your help.
ahh, if your listview is bound to a datasource, you cannot add columns/rows to it. What you can do as an easy workaround, is in your SQL query, get another column that you can use as scratch.
So if you have "SELECT * FROM MYTABLE" you would say "SELECT *, myIDColumn as [Computed Column] FROM MYTABLE"
And then you would have an extra column called "Computed Column" that you can over-write the data in to be your computed value.
Well let's say you have a table with the following columns:
ID | fname | lname | uname
-----------------------------------------
"SELECT *"
would return those 4 columns as:
("ID", "fname", "lname", "uname")
"SELECT *, ID as [Computed Column]"
would return those 4 columns plus an additional column as:
("ID", "fname", "lname", "uname", "Computed Column")
"SELECT *, ID as [Computed Column], ID as [Computed Column2]"
would return those 4 columns plus 2 additional columns as:
("ID", "fname", "lname", "uname", "Computed Column", "Computed Column2")
Got it thanks...For all your help...Now I just got to get it nested with another table like my datagrid. I dont think I'm a fan of Listviews yet...alot I need to learn. Thanks Again.
Well let's say you have a table with the following columns:
ID | fname | lname | uname
-----------------------------------------
"SELECT *"
would return those 4 columns as:
("ID", "fname", "lname", "uname")
"SELECT *, ID as [Computed Column]"
would return those 4 columns plus an additional column as:
("ID", "fname", "lname", "uname", "Computed Column")
"SELECT *, ID as [Computed Column], ID as [Computed Column2]"
would return those 4 columns plus 2 additional columns as:
("ID", "fname", "lname", "uname", "Computed Column", "Computed Column2")
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Tao |
last post by:
I just upgraded .NET framework to 1.1 and VS.Net to 2003 version and
tried to test it out. I created an ASP.NET project using the wizard
and tried to run
it by hitting "F5". I got an exception:...
|
by: Tyro |
last post by:
Can someone shed some light on my error here? Thanks!
Specified cast is not valid.
Exception Details: System.InvalidCastException: Specified cast is not
valid.
Source Error:
Stack Trace:
|
by: PK9 |
last post by:
I am looking for assistance in pinpointing the cause of the following
exception. I am getting a "Specified Cast is not valid" exception on my
page. I am trying to populate a datagrid. One of my...
|
by: Fabian |
last post by:
Hi,
I work with asp.net 2.0 and I have a intermittent error, only happens a few
times a day.
In the page I evaluate a Query String and then I get data form a database.
The code snipped:
...
|
by: VB Programmer |
last post by:
I am setting up forms authentication.
In my code I keep getting this error. Any ideas?
Error....
Server Error in '/LandOLots' Application....
|
by: QA |
last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003
using SQL Server 2005
I am getting the following error:
Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is...
|
by: Alan Z. Scharf |
last post by:
this question in datagrid group for several days with no
repsonse.
I'm hoping for an answer her because of greater activity in this group.
No cross-posting intended. Thanks....
|
by: Gamma |
last post by:
I'm trying to inherit subclass from System.Diagnostics.Process, but
whenever I cast a "Process" object to it's subclass, I encounter an
exception "System.InvalidCastException" ("Specified cast is...
|
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= |
last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm
receiving a "Specified cast is not valid" error that has something to do w/
the keys involved. The stack trace is:
...
|
by: vinrin |
last post by:
Thank for your answer. :-)
call CheckEmptyNode (treeview)
public void CheckEmptyNode( Object N )
{
Microsoft.Web.UI.WebControls.TreeNode menuNode = null; ...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |