0

How can I simply do a list of hours - a date schedule (from 0 to 24) in a listView, that 1st column would show hours seperated by 30 min, 2nd column then will be filled with the name who will reserved that hour.

Something like that: PICTURE.

3
Contributors
12
Replies
15
Views
7 Years
Discussion Span
Last Post by Mitja Bonca
Featured Replies
  • 1
    ddanbe 2,577   7 Years Ago

    Use something like this: [CODE=c#]DateTime dt = new DateTime(); for (int i = 0; i < 10; i++) { Console.WriteLine(dt.ToShortTimeString()); dt = dt.AddMinutes(30); }[/CODE] EDIT: Of course you would add the shorttimestring to your listview! Read More

  • 1
    ddanbe 2,577   7 Years Ago

    Use [B]dt.ToString("HH:mm")[/B] instead of [B]dt.ToString("hh:mm")[/B] Read More

0

I would like to use listView. But even if I would use dgw, I would need the code for listing down the times (from 7.00am to 19.00pm - seperated by half an hour).

I would like to know how to do it. I did a sample for numbers:

double UraZačetka = 7.00;
            double UraNova=0;
            for (int i = 0; i < 26; i++)
            {
                if (i == 0)
                    UraNova = UraZačetka;
                else
                    UraNova = UraNova + 0.5;
                listView1.Items.Add(UraNova.ToString());
            }
1

Use something like this:

DateTime dt = new DateTime();
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(dt.ToShortTimeString());
                dt = dt.AddMinutes(30);
            }

EDIT: Of course you would add the shorttimestring to your listview!

Edited by ddanbe: n/a

0

You can also do your loop natively with a DateTime :

for (DateTime dt = DateTime.Today; dt < DateTime.Today.AddDays(1); dt = dt.AddMinutes(30))
        Console.WriteLine(dt.ToString("hh:mm"));
0

And how would it be if I want to start with 7.am and up to 6.pm)?
Becuase this code starts with 12.00.

0

Try thinking about this a little more....

private void button7_Click(object sender, EventArgs e)
    {
      for (DateTime dt = DateTime.Today.AddHours(7); dt < DateTime.Today.AddDays(1); dt = dt.AddMinutes(30))
        Console.WriteLine(dt.ToString("hh:mm"));
    }

I think you can figure out the 6pm ;)

Edited by sknake: n/a

0

yep :)

for (DateTime dt = DateTime.Today.AddHours(7); dt < DateTime.Today.AddHours(19); dt = dt.AddMinutes(30))
{}

thank you mate for a help.

Just one more thing, when it goes over 12.30 (in the midday) then it goes back to 1.00, I would like to have 13.00. How to do that?

Edited by Mitja Bonca: n/a

0

Just one more thing, when it goes over 12.30 (in the midday) then it goes back to 1.00, I would like to have 13.00. How to do that?

0

thx, I didnt know that until now. Big thanks.
Cheers

bye, bye

Edited by Mitja Bonca: n/a

0

I would like to change my code here a bit, by including dateTimePicker. That the hous in the column will be displayed from it.

Becuase I need to save into database, the time based on the dateTimePicker, not from something else (like DateTime.Today).

I did this code, but it is not starting with 7am like I would like to. It starts with 00.00.

So how would this code be changed that will include dateTimePicker?

for (DateTime Čas = DateTime.Today.AddHours(7); Čas < DateTime.Today.AddHours(19); Čas = Čas.AddMinutes(30))
            {
                dataGridView1.Rows.Add(Čas.ToShortTimeString());
                i++; 
            }
0

Finally did it:

DateTime čas = new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, dateTimePicker1.Value.Day);
            
            for (DateTime Čas = čas.AddHours(7); Čas < čas.AddHours(19); Čas = Čas.AddMinutes(30))
            {
                dataGridView1.Rows.Add(Čas.ToShortTimeString());
            }

Works :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.