Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8908519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:12:01+00:00 2026-06-15T03:12:01+00:00

I made a <List>DateTime class which named GetDataRange so that users can get days

  • 0

I made a <List>DateTime class which named GetDataRange so that users can get days between two specific days.

Then I want to show days in the columns of data grid view. I use a foreach loop, This loop will cause a problem. The problem is it won’t show all days in the columns because I want to show all days in other calendar. see the codes :

for (int i = 0; i < dtEnd.Subtract(dtStart).Days; i++)
        {
            TimeSpan counter = new TimeSpan(i, 0, 0, 0);

            string s1 = "10/9/2012";
            string s2 = "11/10/2012";
            d1 = Convert.ToDateTime(s1);
            d2 = Convert.ToDateTime(s2);

            foreach (DateTime item in GetDateRange(d1, d2))
            {
                s = item.ToShortDateString();
            }


            PersianCalendar p = new PersianCalendar();
            DateTime date = Convert.ToDateTime(s);
            int day = p.GetDayOfMonth(date);
            int month = p.GetMonth(date);
            int year = p.GetYear(date);
            string dt = string.Format("{0}/{1}/{2}", year, month, day);
            dataGridView1.Columns.Add(string.Format("col{0}", i), string.Format("{0} {1}", (dtStart + counter).DayOfWeek.ToString(), dt));


        }

It will show only one day because of that foreach loop. DayOfWeek is working perfectly but the problem is showing the days in foreach loop it will only show one day.

UPDATE

string dt only show one day it won’t show other days.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:12:02+00:00Added an answer on June 15, 2026 at 3:12 am

    You can’t do that. because every time in the loop you are overriding the value. can you show the dates in a new row.

    Try this :

    for (int i = 0; i < dtEnd.Subtract(dtStart).Days; i++)
            {
                TimeSpan counter = new TimeSpan(i, 0, 0, 0);                                       
               dataGridView1.Columns.Add(string.Format("col{0}", i), string.Format("{0}", (dtStart + counter).DayOfWeek.ToString()));
            }
    

    Then add new row for that :

     d1 = dtStart;
            d2 = dtEnd;
            foreach (DateTime item in GetDateRange(d1, d2))
            {
                int day = p.GetDayOfMonth(item);
                int month = p.GetMonth(item);
                int year = p.GetYear(item);
                string dt1 = string.Format("{0}/{1}/{2}", year, month, day);
                listBox1.Items.Add(dt1);
    
            }
            dataGridView1.Rows.Add();
            for (int i = 0; i < dataGridView1.Columns.Count; i++)
            {
                try
                {
                    dataGridView1.Rows[0].Cells[i].Value = listBox1.Items[i];
                }
                catch (Exception)
                {
    
                }
    
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a custom Class named MedinetParse that parses a webrequest. The parsed data
I have made a list view containing two childs. Now i am trying to
The html of this script is made with list items http://www.jeremymartin.name/projects.php?project=kwicks Where can I
I've got a structure which holds names and ages. I've made a linked-list of
I have made a list that uses a list of dates as an index,
Which control approach can i use to quickly provide visual editing of my List
How do I take a basic class that I've made and extract it's properties
I have WebUserControl which made of 3 DropDownLists (day/month/year). It has public property DateTime
I've made a conversation system which shows a list of the conversations you've had.
I made a list from a CSV file. It looks like this: ['18', '29',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.