Click here to Skip to main content
15,878,809 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this is my code

C#
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;
           SP1.Children.Add(neweventlabel);

           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;
           SP1.Children.Add(pb);
       }
   }


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 />
14/01/2013


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

event1<br />
event2


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

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


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
C#
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.

Summery
Problem: Finding the values for the datetime in the string collection
Question: Can you help me find the answer to this problem?
Posted
Comments
Sergey Alexandrovich Kryukov 9-Jan-13 22:43pm    
Why?
—SA

1 solution

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.

—SA
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900