exception error help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: exception error help

  1. #1
    Join Date
    Nov 2004
    Posts
    43

    exception error help

    I have this code that I need help with, it does what I need it to do except when I try to remove column 0 it gives me an exception error but when I try to remove any other columns 1-13 it does not give me this error. The error happens on the underlined and bold line. the exact exception that was thrown is :A first chance exception of type 'System NullReferenceException' and when I try to delete column 0 I get this errorbox that says (Object reference not set to an instance of an object)

    Private Sub CARD_CATALOGDataGridView_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CARD_CATALOGDataGridView.CurrentCellChanged
    Dim i As Integer
    i = CARD_CATALOGDataGridView.CurrentRow.Index
    txtCallnumber.Text = CARD_CATALOGDataGridView.Item(13, i).Value
    txtCallnumber.Text = txtCallnumber.Text.Replace(Chr(32), Chr(13) + Chr(10))
    End Sub

  2. #2
    Join Date
    Feb 2004
    Location
    Longueuil, Québec
    Posts
    577
    The code you sent is useless. It does not try to delete a column and does not have the "underlined and bold line".

    A NullReferenceException happens when you try to reference an object that has not been initialized. If you get it on tryin to delete Columns(0), it usually means that the grid has not been initialized and is empty.
    Jacques Bourgeois
    JBFI
    http://www3.sympatico.ca/jbfi/homeus.htm

  3. #3
    Join Date
    Nov 2004
    Posts
    43

    exception error help

    I am sorry I forgot to underline and put the text in bold that showed the exception error here is that line of code that I was going to underline and make bold:

    i = CARD_CATALOGDataGridView.CurrentRow.Index

    how would I go about initializing the grid

  4. #4
    Join Date
    Feb 2004
    Location
    Longueuil, Québec
    Posts
    577
    If the problem is in the CurrentCellChanged, then the grid is already initialized.

    Events in the DataGridView are often triggered in strange circumstances.

    I suppose that there is no CurrentRow when the event is triggered. This can happen sometimes, such as when you are deleting the last row in the grid.

    You can check to make sure that CurrentRow is available before trying to get its index:

    Code:
    Private Sub CARD_CATALOGDataGridView_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CARD_CATALOGDataGridView.CurrentCellChanged
    
        If CARD_CATALOGDataGridView.CurrentRow IsNot Nothing Then
    
            Dim i As Integer = CARD_CATALOGDataGridView.CurrentRow.Index
            txtCallnumber.Text = CARD_CATALOGDataGridView.Item(13, i).Value
            txtCallnumber.Text = txtCallnumber.Text.Replace(Chr(32), Chr(13) + Chr(10))
    
        End If
    
    End Sub
    Jacques Bourgeois
    JBFI
    http://www3.sympatico.ca/jbfi/homeus.htm

  5. #5
    Join Date
    Nov 2004
    Posts
    43

    Thank You

    Thank You

    Just what I was looking for. It works great.

    Stephen

Similar Threads

  1. Replies: 0
    Last Post: 12-03-2009, 03:22 PM
  2. Replies: 5
    Last Post: 02-06-2006, 12:58 PM
  3. i got marvelous exception
    By mmmobasher in forum .NET
    Replies: 3
    Last Post: 03-07-2005, 10:52 AM
  4. Exception Handling in Exception Handlers
    By David Williams in forum .NET
    Replies: 1
    Last Post: 05-28-2002, 03:19 PM
  5. Replies: 0
    Last Post: 05-03-2001, 10:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center