Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Problem in DataGridView on DateTime column
 

Problem in DataGridView on DateTime column

Hi

I am using VB.Net 2008.

I m binding DataGridView with collection.

I have a 3 fields of DateTime type.

Now at the time of loading it displays empty values in cell where date is null in database.

but after entering any value, when i try to delete it, it shows 1/1/0001.

I want empty cell on delete press.

Please help me to solve this prob.

Thanks in Advance

Thank you

Best Regards

Utkarsh Gajjar

Utkarsh  Tuesday, September 09, 2008 5:13 PM

Hi Utkarsh

Have you encountered some error saying that DateTime cannot be set as null?

If not, how do you set cell’s value to 1/1/0001 while deleting value? Code segment is appreciated.

If you have set the deleted DateTime Value with some value like 1/1/0001, we can make this special value disappear from DataGridView using DataGridView.CellFormatting event like this:

Code Snippet

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)

if (dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString().Equals("1/1/0001"))

null;

Please feel free to let me know more about your progress.

Thanks.

Best wishes

Jun Wang

Jun Wang Tim  Thursday, September 11, 2008 9:38 AM

Hi Utkarsh

Have you encountered some error saying that DateTime cannot be set as null?

If not, how do you set cell’s value to 1/1/0001 while deleting value? Code segment is appreciated.

If you have set the deleted DateTime Value with some value like 1/1/0001, we can make this special value disappear from DataGridView using DataGridView.CellFormatting event like this:

Code Snippet

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)

if (dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString().Equals("1/1/0001"))

null;

Please feel free to let me know more about your progress.

Thanks.

Best wishes

Jun Wang

Jun Wang Tim  Thursday, September 11, 2008 9:38 AM

HiJun Wang

Thank you

Yes , i encountered error of cannot convert DateTime to DBnull.

But , with your code,CellFormatting event it is solved.

Thanksa lot.

Thank you

Best Regards

Utkarsh Gajjar

Utkarsh  Thursday, September 11, 2008 1:28 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView columns automatically added and removed several times...
• How to Bind DataTable Column to DataGridView Column
• design aspect for populating my DataGrid in 3-tier application
• Programmatically setting the selectedindex of a ComboBox doesn't fire SelectedIndexChanged event
• dll or reference problem..
• Datagridview Column Reorder Issue
• Trying to make a simple database application: Updating a ListBox with data related to another
• Grouping and formatting the columns in datagridview
• Problem with DataBinding, MS Access and Integer columns
• DataGridViewComboBoxCell - Allowing values not in the list