-
August 9th, 2021, 05:04 AM
#1
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)
-
August 11th, 2021, 04:53 PM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|