473,395 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

selecting date in a listbox

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!!
Feb 5 '08 #1
5 1216
Plater
7,872 Expert 4TB
Well, if the week "ends" on a sunday, then that means from the current day, you want to go backwards looking for a sunday.

Expand|Select|Wrap|Line Numbers
  1. DateTime dt = DateTime.Now;
  2. while (dt.DayOfWeek != DayOfWeek.Sunday)
  3. {//when this loop exits you will have the date of the sunday you want
  4.    dt = dt.AddDays(-1);
  5. }
  6. //use dt to build the string to look for in your listbox
  7.  
Feb 5 '08 #2
Well, if the week "ends" on a sunday, then that means from the current day, you want to go backwards looking for a sunday.

Expand|Select|Wrap|Line Numbers
  1. DateTime dt = DateTime.Now;
  2. while (dt.DayOfWeek != DayOfWeek.Sunday)
  3. {//when this loop exits you will have the date of the sunday you want
  4.    dt = dt.AddDays(-1);
  5. }
  6. //use dt to build the string to look for in your listbox
  7.  

I was hoping to have this in vb.net....can you assist?
Feb 5 '08 #3
Plater
7,872 Expert 4TB
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
Expand|Select|Wrap|Line Numbers
  1. Dim dt As DateTime = DateTime.Now 
  2. While dt.DayOfWeek <> DayOfWeek.Sunday 
  3.     'when this loop exits you will have the date of the sunday you want 
  4.     dt = dt.AddDays(-1) 
  5. End While 
  6. 'use dt to build the string to look for in your listbox 
  7.  
Feb 5 '08 #4
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
Expand|Select|Wrap|Line Numbers
  1. Dim dt As DateTime = DateTime.Now 
  2. While dt.DayOfWeek <> DayOfWeek.Sunday 
  3.     'when this loop exits you will have the date of the sunday you want 
  4.     dt = dt.AddDays(-1) 
  5. End While 
  6. 'use dt to build the string to look for in your listbox 
  7.  
Thanks Plater!! I'll try to be more ambitious next time!! Thanks again!!
Feb 5 '08 #5
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.
Expand|Select|Wrap|Line Numbers
  1.   Public Sub frmDataEntry_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         gMDB = New OleDb.OleDbConnection
  3.         gMDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data\Cred\Production\Production.mdb"
  4.         gMDB.Open()
  5.         lblID.Text = System.Environment.UserName.Trim 
  6.         GetTeam() 'Mod 1/31/08,loads teams to lstTeam.
  7.     '--Need code to select current week ending date. something like...???
  8.         lstWeekEndingDate.SelectedItem.Equals(GetDate)
  9.     End Sub
Feb 5 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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...
4
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...
4
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...
3
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...
9
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...
3
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...
1
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...
3
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...
9
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....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.