Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
| Search | Today's Posts | Mark Forums Read
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 8th, 2004, 03:28 AM
Authorized User
 
Join Date: Jun 2003
Location: Essendon, Victoria, Australia.
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default Adding Form controls in Datagrid (How to)


  Hey guyz! i was testing a code supplied at the MSDN http://msdn.microsoft.com/library/de...classtopic.asp on using DataGridColumnStyle to add form cotrols to a datagrid (the MSDN its a DateTimePicker).

  However, everytime i run the code it displays the data correct but when i click on the last row i.e the add New row, the code breaks at the after Protected Overloads Overrides Sub Edit( _
    ByVal [source] As CurrencyManager, _
    ByVal rowNum As Integer, _
    ByVal bounds As Rectangle, _
    ByVal [readOnly] As Boolean, _
    ByVal instantText As String, _
    ByVal cellIsVisible As Boolean) function and displays the error msg Cast from type 'DBNull' to type 'String' is not valid. i know the reason why this is so, which is because... their is no datavalue at the [source] variable.

I have tried countless if statement IsDBNull() functions IIf() functions but everytime the code still breaks either inside the function or back at the application.Run(Form1).

If you can help please come to my rescue..coz its stressing me out. I hope its some kind of bug en not my programming skills.

The full function is below:
Protected Overloads Overrides Sub Edit( _
    ByVal [source] As CurrencyManager, _
    ByVal rowNum As Integer, _
    ByVal bounds As Rectangle, _
    ByVal [readOnly] As Boolean, _
    ByVal instantText As String, _
    ByVal cellIsVisible As Boolean)
        MyBase.Edit(source, rowNum, bounds, [readOnly], instantText, cellIsVisible)
        Dim value As DateTime = _
        CType(GetColumnValueAtRow([source], rowNum), DateTime)
        If cellIsVisible Then timePicker.Bounds = New Rectangle _
            (bounds.X, bounds.Y, bounds.Width, _
            bounds.Height)

            timePicker.Value = value
            timePicker.Visible = True
            AddHandler timePicker.ValueChanged, _
            AddressOf TimePickerValueChanged
        Else
            timePicker.Value = value
            timePicker.Visible = False
        End If

        If timePicker.Visible Then DataGridTableStyle.DataGrid.Invalidate(bounds)
        End If
    End Sub

LION OF JUDDAH!
__________________
LION OF JUDDAH!
  #2 (permalink)  
Old July 8th, 2004, 04:37 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

At what point are you testing for DBNull? It sounds like you are passing the result of the query (the data item) directly into the function and it's breaking on the call to the function. You would need to test for DBNull before the call to the function.
  #3 (permalink)  
Old July 8th, 2004, 10:01 PM
Authorized User
 
Join Date: Jun 2003
Location: Essendon, Victoria, Australia.
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey sorry, i used the wrong function to explain. the function below is what am using to test the code and the DbNull issue .

Protected Overloads Overrides Sub Edit( _
    ByVal [source] As CurrencyManager, _
    ByVal rowNum As Integer, _
    ByVal bounds As Rectangle, _
    ByVal [readOnly] As Boolean, _
    ByVal instantText As String, _
    ByVal cellIsVisible As Boolean)

        Dim value As DateTime
        If IsDBNull(GetColumnValueAtRow([source], rowNum)) Then
            value = Today
        Else value = GetColumnValueAtRow([source], rowNum).ToString()
        End If If cellIsVisible Then
            timePicker.Bounds = New Rectangle _
            (bounds.X, bounds.Y, bounds.Width, _
            bounds.Height)

            timePicker.Value = value
            timePicker.Visible = True AddHandler timePicker.ValueChanged, _
            AddressOf TimePickerValueChanged
        Else
            timePicker.Value = value
            timePicker.Visible = False
        End If

        If timePicker.Visible Then
            DataGridTableStyle.DataGrid.Invalidate(bounds)
        End If
    End Sub

The code still has the problem as i described above en it breaks back at the application.Run(Form1).

Thanks for your reply

LION OF JUDDAH!
  #4 (permalink)  
Old July 9th, 2004, 08:25 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I'm not sure what the problem is. I have never dealt with a CurrencyManager.
  #5 (permalink)  
Old July 11th, 2004, 09:17 AM
Authorized User
 
Join Date: May 2004
Location: , , .
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

my friend had same error message few minutes ago. if it is a database, have you checked that the value of a particular field in the database that is assigned to a variable is not null?

  #6 (permalink)  
Old July 13th, 2004, 12:24 AM
Authorized User
 
Join Date: Jun 2003
Location: Essendon, Victoria, Australia.
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Don't worry i figured it out.

If anybody comes across a similar problem: Make sure you override GetColumnValueAtRow function and inside it call the Base class function then return the value after checking for nulls.

Or u can try jus calling the base function where needed.

It sounds flueky but it worked fine for me.

LION OF JUDDAH!


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding controls on vba form from an addin narendrapawar Pro VB 6 1 April 25th, 2010 04:59 PM
Adding controls to a form Scootterp Access VBA 2 August 4th, 2009 02:32 PM
Adding controls to a form based on data received jontheniceguy Visual Basic 2005 Basics 0 April 7th, 2006 10:07 AM
Adding text/controls from one form to another Paula222 Access VBA 1 February 24th, 2006 10:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.