Click here to Skip to main content
15,911,531 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(item + 1);
                   DateTime yourDateTime2 = DateTime.Parse(item + 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);
               }
           }



the error is, only the one label is posted, its meant to post the progressbar too, so I found out where the error is it is

C#
DateTime yourDateTime = DateTime.Parse(item + 1);
                   DateTime yourDateTime2 = DateTime.Parse(item + 2);


but I don't understand why its not working.

this is what it looks like in the string collection


eventname<br />
9/01/2013<br />
20/01/2013


so this is what its ment to look like in the program

eventname
|-----progressbar-with the values-----|

its just a ruff visual of it.
can some one please help me solve the problem?
Posted

It is not working, it cannot compile. What's your problem, ashamed to admit it? :-)

This is just gibberish: DateTime.Parse(item + 1); item is string, that's correct, because the method Parse expects a string parameter, but you cannot add 1 to a string.

It's not even clear what could you probably meant by "+1". Adding a day? an hour? If this was something like this, you should first parse item to obtain an instance of DateTime and then use one of the functions adding some time span to the resulting time.

—SA
 
Share this answer
 
Comments
[no name] 9-Jan-13 2:24am    
in (item + 1) trying to select the item, for example, in the stringcollection, lets say i have 5 lines, i want to select line 3, and i do this by, selecting line 2 and adding 1
Sergey Alexandrovich Kryukov 9-Jan-13 2:28am    
No, you are not trying to select the item. I already explained...
I am tempted to say "stop developing UI, you are not ready yet, first learn some elementary basics of programming"... you see almost said that. :-)
—SA
[no name] 9-Jan-13 2:57am    
lets say i got 5 strings in my stringcollection, and they go in order like this

yo1
yo2
yo3
yo4

I want to select "yo3"

I already know the line number of "yo2" but not "yo3"
So, because I don't know "yo3"
I will need to use an index or something
because its an unknown, I want to do somthing like

select the index in line 2 (which is "yo2") then add 1 to the index in the stringcollection, which will bring me down 1 line, and then it will give me "yo3"
Jibesh 9-Jan-13 3:02am    
Check my solution. since your collection is fixed you can access your data with index you want.
Jibesh 9-Jan-13 2:55am    
hmm... seriously .. you should start looking how Collection works, and before that you must know what your code does.

you are already iterating a collection so use an counter to check the iteration. do spend learning some basics before going further it will save your time for future development.
As per your comments you should try the following code to solve this.

C#
DateTime yourDateTime = DateTime.Parse(Properties.Settings.Default.DatesEventNames[1]);
DateTime yourDateTime2 = DateTime.Parse(Properties.Settings.Default.DatesEventNames[2]);


mean time you should be careful in accessing this collection. check the array count else it blows your application.
 
Share this answer
 

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