C# 为什么我会在一周中的某一天崩溃?
我的系统时钟是2014年9月16日(星期二) 但在代码中,我总是跳到星期一C# 为什么我会在一周中的某一天崩溃?,c#,datagridview,switch-statement,datagridviewrow,C#,Datagridview,Switch Statement,Datagridviewrow,我的系统时钟是2014年9月16日(星期二) 但在代码中,我总是跳到星期一 DayOfWeek dow = new DateTime().DayOfWeek; int columnNumber = 0; columnNumber = columnNumber + 0; foreach ( DataGridViewRow row in dataGridView1.Rows ) { switch ( dow ) { case DayOfWeek.Monday: columnN
DayOfWeek dow = new DateTime().DayOfWeek;
int columnNumber = 0;
columnNumber = columnNumber + 0;
foreach ( DataGridViewRow row in dataGridView1.Rows )
{
switch ( dow )
{
case DayOfWeek.Monday:
columnNumber = 4;
if ( (bool) row.Cells[4].Value == true ) // crashing here with NullReferenceException
{
row.Cells["activeTodayDataGridViewCheckBoxColumn"].Value = true;
}
break;
我有一个DataGridView
- 第0-3列为
文本
- 列4-9为
DataGridViewCheckBoxColumn
new DateTime()
不提供今天的日期,而是提供DateTime的默认值
您想将该行更改为:
DayOfWeek-dow=DateTime.Now.DayOfWeek
new DateTime()
不提供今天的日期,而是提供DateTime的默认值
您想将该行更改为:
DayOfWeek-dow=DateTime.Now.DayOfWeek代码>我回答了一个问题。你应该每个问题问一个问题。请下次阅读。DateTime
的第一个示例显示newdatetime()
默认为1/1/0001 12:00:00 AM.
甚至只使用调试器。不需要花太多的精力就可以注意到您正在创建的DateTime
对象不是今天的日期。您可能应该尝试使用LINQ。我回答了一个问题。你应该每个问题问一个问题。请下次阅读。DateTime
的第一个示例显示newdatetime()
默认为1/1/0001 12:00:00 AM.
甚至只使用调试器。不需要花太多的精力就可以注意到您正在创建的DateTime
对象不是今天的日期。您可能应该尝试使用LINQ。