Results 1 to 3 of 3

Thread: [RESOLVED] Accessing Last Row of a DataGrid

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    59

    Resolved [RESOLVED] Accessing Last Row of a DataGrid

    I am trying to access a column on the last row of my data grid but I am getting the following error - System.NullReferenceException was unhandled
    Message="Object reference not set to an instance of an object."

    Below I have included my vb.net code

    Count = Me.DataGridView1.Rows.Count
    MsgBox("70 " + Me.DataGridView1.Rows(Me.DataGridView1.Rows.Count - 1)
    MsgBox("71 " + Me.DataGridView1.Rows(19).Cells.Item(4).Value.ToString) <---- This is the line generating the exception.

    Thanks

  2. #2
    Addicted Member
    Join Date
    Oct 2006
    Location
    Chennai, India
    Posts
    198

    Re: Accessing Last Row of a DataGrid

    The error was due the particular cell has the null values which when try converting to the string data type its throws an exception.

    So before getting the value try check for null string in the cell. either isnull or <>""
    Regards
    Srinivasan Baskaran
    India

  3. #3
    Addicted Member
    Join Date
    Oct 2006
    Location
    Chennai, India
    Posts
    198

    Re: Accessing Last Row of a DataGrid

    you can check something like

    Code:
    drv[x].ToString().Trim() == System.DBNull.Value.ToString()
    Regards
    Srinivasan Baskaran
    India

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width