Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

C# winform remove date from datagridview / Access database

$
0
0

I have a winform with datagridview MS Access database. I have 2 columns linked to datetimepicker. In code I copy the date from one column to the other and the copied cell is blank. when I reopen the form the blank cell shows 12/30/1899. How can i keep it blank until I enter another date?

This is the code I use to copy from one cell to the other (button click)

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
       {

           if (e.ColumnIndex == dataGridView1.Columns [19].Index)
           {

               {
                   dataGridView1.CurrentRow.Cells[16].Value = dataGridView1.CurrentRow.Cells[17].Value;
                   dataGridView1.CurrentRow.Cells[17].Value =  "";
               }
           }
       }
   }
   }

I have tried the below code also. With no luck

 private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (formatting.Value != null)
            {
                if (e.ColumnIndex == 17)
                {
                    if ((DateTime)dataGridView1.CurrentRow.Cells[17].Value == DateTime.MinValue)
                    {
                        formatting.Value = "";
                    }
                }
            }
        }
    }
}


Booney440


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>