-
May 3rd, 2014, 02:41 PM
#1
C# to VB.net Invoke error
Hey all I am trying to figure out how to get the code below to work in VB.net. I already converted it from C# to VB.net:
Code:
Dim dt As New DataTable()
Dim dr As DataRow
dt.Columns.Add("Name")
dt.Columns.Add("Number")
For Each item As KeyValuePair(Of String, String) In vCardReader.dicNumName
dr = dt.NewRow()
dr(0) = item.Value
dr(1) = item.Key
dt.Rows.Add(dr)
Next
If InvokeRequired Then
Me.Invoke(New MethodInvoker(
Sub()
contactNameNumList.DataSource = dt
contactNameNumList.AllowUserToResizeRows = False
contactNameNumList.AllowUserToResizeColumns = False
contactNameNumList.AllowUserToOrderColumns = False
contactNameNumList.CellBorderStyle = DataGridViewCellBorderStyle.None
contactNameNumList.Columns(0).Width = 30
contactNameNumList.Columns(1).Width = contactNameNumList.Width / 2 - 25
contactNameNumList.Columns(2).Width = contactNameNumList.Width / 2 - 25
End Sub))
Else
contactNameNumList.DataSource = dt
contactNameNumList.AllowUserToResizeRows = False
contactNameNumList.AllowUserToResizeColumns = False
contactNameNumList.AllowUserToOrderColumns = False
contactNameNumList.CellBorderStyle = DataGridViewCellBorderStyle.None
contactNameNumList.Columns(0).Width = 30
contactNameNumList.Columns(1).Width = contactNameNumList.Width / 2 - 25
contactNameNumList.Columns(2).Width = contactNameNumList.Width / 2 - 25
End If
However, when I run the program, the error I get for the above code is this:
> Object reference not set to an instance of an object.
How can I correct this error?
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
|