CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2021
    Posts
    6

    Exceptional Handler - Buffer cannot be null

    Hi,

    I have a datagridview and on cellmouseclick the following code is called:

    Code:
    Private Sub DgTenantDetails_CellMouseClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DgTenantDetails.CellMouseClick
    
            'Dim conn As SqlConnection = GetDbConnection()
    
            If e.RowIndex >= 0 Then
    
                Call TenantsDetailsDisable()
                BtnUpdate.Enabled = False
    
                Dim img As Byte()
                img = DgTenantDetails.Item(6, e.RowIndex).Value
                'img = DgTenantDetails.Rows(e.RowIndex).Cells(6).Value
                Dim ms As New MemoryStream(img)
    
    
                Dim row As DataGridViewRow = DgTenantDetails.Rows(e.RowIndex)
    
                TxtFNameUp.Text = row.Cells(1).Value.ToString
                TxtLNameUp.Text = row.Cells(2).Value.ToString
                TxtTelUp.Text = row.Cells(3).Value.ToString
                TxtEmailUp.Text = row.Cells(4).Value.ToString
                TxtNationalIDUp.Text = row.Cells(5).Value.ToString
                PictureBox2.Image = Image.FromStream(ms)
                PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage
    
            End If
        End Sub
    On the form, I have a 'Search By' with a dropdownlist i.e., ALL, firstname, lastname.

    On Formload by default it has 'ALL' selected with all the records displayed on the datagridview.

    Now, if I 'Search By' - firstname and enter details on the textbox the datagridview gets populated accordingly.

    The issue is if I click a cell on the datagridview to display the content on another panel with textboxes and picturebox I get the following error message:

    Code:
    System.ArgumentNullException: 'Buffer cannot be null.
    Parameter name: buffer'
    The following code is highlighted in GREEN

    Code:
    Dim ms As New MemoryStream(img)
    N/B: When I click cell when the datagridview is populated on formload i.e., 'ALL' is selected by default - this problem doesn't exist

    Thanks

    Code:
    Dim ms As New MemoryStream(img)

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,494

    Re: Exceptional Handler - Buffer cannot be null

    Set a breakpoint and debug your code. You'll be able to see the exact line where the variable is null. From there you can fingure out what to do to fix it.

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

Featured