Click here to Skip to main content
15,892,643 members

C# - Getting a line number and the string

C.CoderCreator asked:

Open original thread
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?
Tags: C#

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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