Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DatePicker Cell Disappearing
 

DatePicker Cell Disappearing

Hai

I had added a DateTimePicker Excataly like in this url [ http://msdn2.microsoft.com/en-us/library/7tas5c80.aspx ] .


My problem is while. I had setted the allowadding property of the DataGridView to true, and i binded the DataGridView with dataset. While trying to add data in the rows of the grid manually. DateTimePicker will disappear and the DataTimePicker value will return like this [ this.value = {} ].


If anybody have any solution for this. Please help me.


Thanks and Regards

Rajeev

Raj - WebDev Raj  Tuesday, July 03, 2007 11:25 AM

Hi rajeev,

Try to change the InitializeEditingControl Method in the CalendarCell Class to this:

Code Snippet

publicoverride void InitializeEditingControl(int rowIndex, object

initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)

{

// Set the value of the editing control to the current cell value.

base.InitializeEditingControl(rowIndex, initialFormattedValue,

dataGridViewCellStyle);

CalendarEditingControl ctl =

DataGridView.EditingControl as CalendarEditingControl;

if (this.Value.ToString() != "")

ctl.Value = (DateTime)this.Value;

else

ctl.Value = DateTime.Now;

}

Hope this helps.

Regards

Rong-Chun Zhang  Wednesday, July 04, 2007 10:43 AM

Hi rajeev,

Try to change the InitializeEditingControl Method in the CalendarCell Class to this:

Code Snippet

publicoverride void InitializeEditingControl(int rowIndex, object

initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)

{

// Set the value of the editing control to the current cell value.

base.InitializeEditingControl(rowIndex, initialFormattedValue,

dataGridViewCellStyle);

CalendarEditingControl ctl =

DataGridView.EditingControl as CalendarEditingControl;

if (this.Value.ToString() != "")

ctl.Value = (DateTime)this.Value;

else

ctl.Value = DateTime.Now;

}

Hope this helps.

Regards

Rong-Chun Zhang  Wednesday, July 04, 2007 10:43 AM
Hai

Thanks, i done that by setting a DefaultCellStyle.NullValue to the DataGridView cell and in the date picker cell, if this.value == Db null.value i make the this.value as the current date. i passed the Null value to cell also as also Current Date .

One Common problem with the DateTimePicker Cell is, when i change the format of the date. Suppose if i change the format to dd/MM/yyyy . we can't compare the date inside the DataGridView cell with the any date inside the form . dam things always try to pass back the date as what format we are providing.

Do u have any solution for this ?

Thanks and Regards
Rajeev



Raj - WebDev Raj  Thursday, July 05, 2007 5:51 AM

Hi Rajeev,

I have tested it. It worked here.Could you show some code about how you compare the date. Below is the codeI am used.

Code Snippet

DateTime celltime = DateTime.Parse(this.dataGridView1[1, this.dataGridView1.CurrentCell.RowIndex].Value.ToString());

int a = DateTime.Compare(DateTime.Now, celltime);

MessageBox.Show(a.ToString());

Hope this helps.

Regards

Hai

Thanks. My problem is while parsing the date time with different format, in the DataGridView cell and with the date in the DateTimePicker. What happening is in both controls the date format is dd/MM/yyyy. Date picker will parse the correct datetime while comparing, but the date in the DataGridView cell will pass a string like d/M/yyyy or dd/MM/yyyy. so every time it will error. String cannot be regonised as a valid date time. if the date format is in default format it won't create any problem.

Regards and Thanks in Advance
Rajeev

Raj - WebDev Raj  Friday, July 06, 2007 5:59 AM

Hi Rajeev,

I have tested it using the format string like 'd/M/yy', it worked well. When I use theDataGridViewCell.FormattedValue,I encounter the same error as you. So I guess you did not use the DataGridViewCell.Value.

Hope this helps.

Regards

Rong-Chun Zhang  Friday, July 06, 2007 8:41 AM

You can use google to search for other answers

Custom Search

More Threads

• ListChangedType.Reset
• DataGridView doesn't updates after calling DataTable.RejectChanges
• How to get or read the last letter from a text box? - Vb.net or VS 2005
• binding datagrid view to another data grid view
• NumericUpDown Size
• set delay between moves in ListView
• DataGridView vs DataGrid bound to DataView
• how to check if a datatable has a new row added?
• Sample application icons for Visual C#
• Implementing DataBinding in webControls in asp.net 2.0