选择的月份日期想要使用c sharp在datagridview中显示 [英] selected month date want to display in datagridview using c sharp

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

问题描述

我希望选择的月份日期想要使用c sharp在datagridview中显示。



我的代码如下;



 private void Faculty_Available_Calendar_DateChanged(object sender,DateRangeEventArgs e)
{

DGVCalendar.Rows.Clear();
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 ++;
}

}





在datagridview中输出如下; (当我选择行军月份意味着月份所有日期都要显示在datagridview中)



选择月份(名称)列名称)



复选框2013年1月3日至2013年3月31日(datagridview中的dsiplay)





当我在运行模式下选择月份(月份日历控件),错误显示如下;



字符串未被识别为有效布尔值。''



当我在datagridview中添加Checkbox时会发生此错误。



假设我删除了datagridview中的Checkbox,正确地解决了原因?



我想添加复选框,以便选择日期并保存在数据库中。

解决方案

你''我添加了日期左侧的复选框,所以它实际上在单元格[0]。



如果你删除CheckBox然后日期再次成为单元格[0 ]。



你现在可以选择......

要么把t他在日期右侧的CheckBox列(Cells [1])

OR

更改行

 DGVCalendar.Rows [row] .Cells [ 0] .Value 

 DGVCalendar.Rows [row] .Cells [ 1 ]。值





更好的是,定义一些const值,例如 const int DateColumn = 0 并使用

 DGVCalendar.Rows [row] .Cells [DateColumn] .Value 


I want selected month date want to display in datagridview using c sharp.

My Code as follows;

private void Faculty_Available_Calendar_DateChanged(object sender, DateRangeEventArgs e)
        {
              
             DGVCalendar.Rows.Clear();
             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++;
            }
         
        }



In datagridview ouput as follows; (when i select march month means that month all dates want to display in datagridview)

Select Month(Name) column Name)

Checkbox 1/3/2013 to 31/3/2013 (dsiplay in datagridview)


When i select the month in (Month Calendar Control) in run mode,Error shows as follows;

string was not recognized as valid Boolean.''

This error happen when i add Checkbox in datagridview.

suppose i remove the Checkbox in datagridview, Correctly working why?

I want to add checkbox, so that select the date and save in database.

解决方案

You''ve added the check box to the left of the date so it is actually in Cells[0].

If you remove the CheckBox then the date again becomes Cells[0].

You have a choice now ...
Either put the CheckBox column to the right of the date (Cells[1])
OR
change the line

DGVCalendar.Rows[row].Cells[0].Value

to be

DGVCalendar.Rows[row].Cells[1].Value



Better yet, define some const values e.g. const int DateColumn = 0 and use

DGVCalendar.Rows[row].Cells[DateColumn].Value 


这篇关于选择的月份日期想要使用c sharp在datagridview中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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