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

    Exceptional Handler - Buffer cannot be null


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

    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:

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

    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


    Dim ms As New MemoryStream(img)

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

    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