Advertisement

07.07.2008 at 09:57PM PDT, ID: 23545510
[x]
Attachment Details

DateTimePicker in DataGridView insert problem

Asked by bd9000 in Microsoft Visual Basic.Net, .NET Framework 2.x, .NET Framework 3.x versions

Tags:

I put in a DateTimePicker into a DataGridView control just like in the http://msdn.microsoft.com/en-us/library/7tas5c80.aspx
article.  The only problem is that when I try to insert another row, the DateTimePicker cell goes blank and clicking in the cell will generate an exception "Conversion from type 'DBNull' to type 'Date' is not valid."  in the following routine:
    Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, _
        ByVal initialFormattedValue As Object, _
        ByVal dataGridViewCellStyle As DataGridViewCellStyle)

        ' Set the value of the editing control to the current cell value.
        MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)

        Dim ctl As CalendarEditingControl = CType(DataGridView.EditingControl, CalendarEditingControl)
        ctl.Value = CType(Me.Value, DateTime)  '<--- ERROR OCCURS HERE
    End Sub

The value is DBNull - the problem is that the Date cell is blanking out before the dataset row is updated (simply moving over to the next cell is somehow forcing the datagridview to update).  Is this the correct behavior? Or is this a bug?
Start Free Trial
[+][-]07.08.2008 at 06:06AM PDT, ID: 21953341

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 04:50PM PDT, ID: 21959412

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 05:01AM PDT, ID: 21962545

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 02:47PM PDT, ID: 21968713

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.18.2008 at 06:13AM PDT, ID: 22035385

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual Basic.Net, .NET Framework 2.x, .NET Framework 3.x versions
Tags: VB.NET FW2.0 WinForms
Sign Up Now!
Solution Provided By: rkulp
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.18.2008 at 01:53PM PDT, ID: 22039706

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.12.2008 at 04:35PM PDT, ID: 22217983

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.12.2008 at 05:49PM PDT, ID: 22218307

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.14.2008 at 10:31AM PDT, ID: 22232329

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]08.20.2008 at 05:11AM PDT, ID: 22268507

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628