Question select unique date values from listbox

dmarkus100

Member
Joined
Jul 11, 2010
Messages
15
Programming Experience
1-3
hi

I have a listbox which is populated from a sql table. I need to select unique month values from the dates in this listbox.

Dates are, for example:

21/09/2010
22/09/2010
21/07/2010
09/06/2010

I need to extract september, june and july only from the above, sort them and display them in a another listbox.

All help will be gratefully received.

Thanks
 
As you're using .NET 3.5, you have LINQ at your disposal, which excels at this sort of thing. Now, I'm going to assume that you actually do have Date values in your ListBox and not Strings:
VB.NET:
Me.ListBox2.Items.AddRange((From d In Me.ListBox1.Items.Cast(Of Date)() _
                            Order By d.Month _
                            Select d.ToString("MMMM") Distinct).ToArray())
 
Back
Top