选定的月份日期将使用月份日历控件显示在datagrdiveiw中 [英] selected month date will display in datagrdiveiw using Month calendar control

查看:101
本文介绍了选定的月份日期将使用月份日历控件显示在datagrdiveiw中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

条件:选定月份所有日期都希望在datagridview中显示Datagridview并且不想要其他月份日期。



选择的月份日期将显示在datagrdiveiw中使用Csharp中的月历。



对于该代码如下;

 私有  void  Faculty_Available_Calendar_DateChanged( object  sender,DateRangeEventArgs e)
{
DateTime dt1 = Faculty_Available_Calendar.SelectionStart;
dt1 = new DateTime(dt1.Year,dt1.Month, 1 );
DateTime dt2 = dt1.AddMonths( 1 );
int numDays =(dt2 - dt1).Days;
if (DGVCalendar.RowCount < numDays)
{
DGVCalendar.RowCount = numDays;
}
int row = 0 ;
while (dt1 < dt2)
{
DGVCalendar。行[row] .Cells [ 0 ]。值= dt1.ToString( DD-MM-YY);
dt1 = dt1.AddDays( 1 );
row ++;
}
}

当我选择4月月份那个月日期显示时和3月月日期31/03/2013也显示为什么?



来自我的代码我犯了什么错误?



请帮帮我。



在Datagridview中输出如下



当我选择该月份的月份日期时,仅显示在datagridview中。



月(选择4月份)

2013年4月4日

至30/4/2013



31/3/2013。



条件:选定月份所有日期都希望在datagridview中显示Datagridview并且不想要其他月份日期。

解决方案

问题是您每次都没有清除DGV。您必须在之前的运行(31天)和4月(30天)中选择3月,以便3月的最后一天不被新月覆盖。



int numDays ... 之前使用

 DGVCalendar.Rows.Clear(); 

c $ c>

当然行数现在总是为零,所以你可以在那之后立即整理 if 语句


Condition:Selected Month All Dates want to display Datagridview and dont want other month date in datagridview.

selected month date will display in datagrdiveiw using Month Calendar in Csharp.

For that code as follows;

private void Faculty_Available_Calendar_DateChanged(object sender, DateRangeEventArgs e)
{
    DateTime dt1 = Faculty_Available_Calendar.SelectionStart;
   dt1 = new DateTime(dt1.Year, dt1.Month, 1);
    DateTime dt2 = dt1.AddMonths(1);
    int numDays = (dt2 - dt1).Days;
    if (DGVCalendar.RowCount < numDays)
    {
        DGVCalendar.RowCount = numDays;
    }
    int row = 0;
     while (dt1 < dt2)
    {
         DGVCalendar.Rows[row].Cells[0].Value = dt1.ToString("dd-MM-yy");
          dt1 = dt1.AddDays(1);
        row++;
    }
}

when i select April Month That Month Date is display and March month date 31/03/2013 also display why?

from my code what is the mistake i made?

Please help me.

Output as follows in Datagridview

when i select april month that month date only display in datagridview.

Month (seleting April Month)
1/4/2013
to 30/4/2013
and
31/3/2013.

Condition:Selected Month All Dates want to display Datagridview and dont want other month date in datagridview.

解决方案

The problem is that you are not clearing the DGV down each time. You must have selected March on a previous run (31 days) and then April (30 days) so the last day in March is not being overwritten by the new month.

Use

DGVCalendar.Rows.Clear();

before the while loop after the int numDays ...
Of course the number of rows will now always be zero so you can tidy up the if statement immediately after that as well


这篇关于选定的月份日期将使用月份日历控件显示在datagrdiveiw中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆