I have a listbox populated with all the week ending dates of 2008 where Sunday is the last day of the week (1/6/08, 1/13/08, etc.)
I need to select the most current week ending date upon the form load. So, since today is 2/5/08, the date selected should be 2/3/08. I have struggled with this one for a while so any and all help is appreciated. Thanks!!
5 1216
Well, if the week "ends" on a sunday, then that means from the current day, you want to go backwards looking for a sunday. -
DateTime dt = DateTime.Now;
-
while (dt.DayOfWeek != DayOfWeek.Sunday)
-
{//when this loop exits you will have the date of the sunday you want
-
dt = dt.AddDays(-1);
-
}
-
//use dt to build the string to look for in your listbox
-
Well, if the week "ends" on a sunday, then that means from the current day, you want to go backwards looking for a sunday. -
DateTime dt = DateTime.Now;
-
while (dt.DayOfWeek != DayOfWeek.Sunday)
-
{//when this loop exits you will have the date of the sunday you want
-
dt = dt.AddDays(-1);
-
}
-
//use dt to build the string to look for in your listbox
-
I was hoping to have this in vb.net....can you assist?
Well ok, it's really almost identical code, you shoulda been able to gleen it from what I posted, considering I did like all the work on that part for you :-P -
Dim dt As DateTime = DateTime.Now
-
While dt.DayOfWeek <> DayOfWeek.Sunday
-
'when this loop exits you will have the date of the sunday you want
-
dt = dt.AddDays(-1)
-
End While
-
'use dt to build the string to look for in your listbox
-
Well ok, it's really almost identical code, you shoulda been able to gleen it from what I posted, considering I did like all the work on that part for you :-P -
Dim dt As DateTime = DateTime.Now
-
While dt.DayOfWeek <> DayOfWeek.Sunday
-
'when this loop exits you will have the date of the sunday you want
-
dt = dt.AddDays(-1)
-
End While
-
'use dt to build the string to look for in your listbox
-
Thanks Plater!! I'll try to be more ambitious next time!! Thanks again!!
Ok....I need to know how to select a date in a listbox based on a returned value of the week ending date.
I will want this to occur in the load event of the form. - Public Sub frmDataEntry_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
gMDB = New OleDb.OleDbConnection
-
gMDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data\Cred\Production\Production.mdb"
-
gMDB.Open()
-
lblID.Text = System.Environment.UserName.Trim
-
GetTeam() 'Mod 1/31/08,loads teams to lstTeam.
-
'--Need code to select current week ending date. something like...???
-
lstWeekEndingDate.SelectedItem.Equals(GetDate)
-
End Sub
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jeffrey Barish |
last post by:
I have an application that produces two listboxes. I would like to be
able to select one of the items in the first listbox and one of the
items in the second listbox. However, when I make my...
|
by: Geir Baardsen |
last post by:
Hi!
I have the following headpuzzle:
On a form (frmAgenda) I have a calendar control and a listbox.
When user clicks date in calendar, the listbox will show some
information that will be...
|
by: Ron |
last post by:
I've got a listbox that holds a list of groups. Users can
select a group, hit the remove button and the group
should be removed from the listbox. The only problem is
that no matter which group you...
|
by: larry mckay |
last post by:
anyone have the code to select and listview item or row (subitems)
after a doubleclick event from a listview.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate...
|
by: Fred Morrison |
last post by:
I need to bind a true date value to a listbox control via a DataSet that
contains true date values (not strings). The problem is, the list contains
the time (always midnight in my case). Other...
|
by: Eric Lemmon |
last post by:
Greetings,
I have a VB.NET Windows app where I bind a listbox to a DataView column that contains date values. In this list, however, only the date (not the time) is relavent, so I want to...
|
by: vunderusaf |
last post by:
I have a listbox on a form that is selecting using named FinalQuery:
SELECT ., .,
.
FROM FinalQuery;
Now I have a text field with a date on this form and I'd like to use
that date as the...
|
by: is49460 |
last post by:
Hello,
I have a form with various controls but to simplify the problem let’s say I have 2 listboxes. The selection in listbox1 controls RowSource of the listbox2. For example lstCars contains car...
|
by: ahilar12 |
last post by:
1. <head>
2. <script type="text/javascript">
3. </script>
4. </head>
5. <body>
6. <form>
7. <select name="team" id="mylist" >
8. <option></option>
9....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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: 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...
| |