Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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;
                    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
 
 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
9/01/2013
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 8-Jan-13 18:49pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It is not working, it cannot compile. What's your problem, ashamed to admit it? Smile | :)
 
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
  Permalink  
Comments
TechXSoftware at 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 at 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
TechXSoftware at 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 at 9-Jan-13 3:02am
   
Check my solution. since your collection is fixed you can access your data with index you want.
jibesh at 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.
TechXSoftware at 9-Jan-13 19:40pm
   
how do i delete this question? because apparently this is useless
Sergey Alexandrovich Kryukov at 9-Jan-13 19:43pm
   
I would do it, but we usually don't remove questions which already got answers, because the inquirer is not the only reader of them. —SA
TechXSoftware at 9-Jan-13 20:15pm
   
well none of them are the answer, i'll restart the question, don't think people understand the question
Sergey Alexandrovich Kryukov at 9-Jan-13 21:00pm
   
People don't have to understand it all, especially when you do net really collaborate. Do you know this well-known proverb: "I don't need to eat all the egg to know it's bad"? I've shown you one bug, this should be enough to make a first step, and then go ahead. You, however, did not show any sign that you sorted it our or even tried. However, the problem is that you maybe not ready to do what you try. Go back, learn the basics. —SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

As per your comments you should try the following code to solve this.
 
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.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Guruprasad.K.Basavaraju 400
1 Shai Vashdi 334
2 Sergey Alexandrovich Kryukov 305
3 OriginalGriff 265
4 Peter Leow 171
0 Sergey Alexandrovich Kryukov 8,979
1 OriginalGriff 5,280
2 Peter Leow 4,010
3 Maciej Los 3,535
4 Abhinav S 3,263


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid