Click here to Skip to main content
12,956,410 members (77,025 online)
Rate this:
Please Sign up or sign in to vote.
See more:
this is my code

         int i = 0;
            foreach (string item in Properties.Settings.Default.DatesEventNames)
                //add the headings
                if ((i++ % 3) == 0)
                    //add label
                    Label neweventlabel = new Label();
                    neweventlabel.Content = item;
                    DateTime yourDateTime = DateTime.Parse(Properties.Settings.Default.DatesEventNames[i]);
                    DateTime yourDateTime2 = DateTime.Parse(Properties.Settings.Default.DatesEventNames[i + 2]);
                    //add progressbar 
                    ProgressBar pb = new ProgressBar();
                    pb.Maximum = (yourDateTime - yourDateTime2).TotalDays;
                    pb.Value = (yourDateTime - DateTime.Now.Date).TotalDays;
                    pb.Height = 20;

this is what is looks like in the stringcollection

event1<br />
10/01/2013<br />
13/01/2013<br />
event3<br />
12/01/2013<br />

what this code dose at the moment is grabs every third string in stringcollection so it looks like this

event1<br />

but i want to out a progressbar inbetween them so it looks like this

event1<br />
|-----progressbar-----|<br />
event2<br />

right now im trying to give the values to the progressbars. for example I want these vales from event1

Start Date - 10/01/2013<br />
End Date - 13/01/2013<br />
Todays Date - ??/??/????

so for the progress bar it will have

The maximum = (start date to end date)<br />
The Value = (todays date to the end date)

Im having trubble getting the values for the convention in the strings in the dates

So lets say on this line of code
int i = 0;
          foreach (string item in Properties.Settings.Default.DatesEventNames)
              //add the headings
              if ((i++ % 3) == 0)

lets say it lands on event2, I want it to get that strings line number lets just say its line 3, then I want it to go down 1 line number, which will make it line 4, and in line 4 would be the date. and this will give me the values. I hope this explains it, please re-read this question in-case you miss something.

Problem: Finding the values for the datetime in the string collection
Question: Can you help me find the answer to this problem?
Posted 9-Jan-13 16:28pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Of course, this problem is not hard to solve. But why? You are coming to the problem from a wrong side.

This is one of the typical beginners' mistakes these days: an attempt to work with string representation of data instead of data itself, and then having to deal with related problems, spending your time which deserves better use.

If you want to have a collection of something with string and time data, create a class or a structure with string, time and other members. Make a collection of items of this type. Most collection types are generic, since .NET v.2.0, so collections are agnostic to the item types.

All your suffering will be reduced to few line of very clear and readable code.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,869
CHill60 3,550
Maciej Los 3,302
ppolymorphe 2,080
Jochen Arndt 1,973

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100