I’m trying to extend the GridView class to always show the header and footer even when the datasource is empty by using the code I found online (link). However, the code is written in C# but I use VB.
What is the VB equivalent of the following?
public event MustAddARowHandler MustAddARow;
Is there a way around VB.NET not allowing events to return a type?
Also, I cannot convert the following function because of the error below.
Code:
Protected Function OnMustAddARow(ByVal data As IEnumerable) As IEnumerable
If MustAddARow = Nothing Then 'Error on MustAddARow'
Throw New NullReferenceException("The datasource has no rows. You " _
& "must handle the 'MustAddARow' Event.")
End If
Return MustAddARow(data) 'Error on MustAddARow'
End Function
Error: Public Event MustAddARow(data As System.Collections.IEnumerable)’ is an event, and cannot be called directly. Use a ‘RaiseEvent’ statement to raise an event.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Like this:
Public Event MustAddRow(data As IEnumerable)
Method 2
Note: This answer is actually wrong. My bad. The syntax shown is correct (which is why I won’t delete this answer right away), but it won’t compile, since events — which are usually multi-cast delegates — aren’t allowed to return a value in VB.NET.
Event declaration:
Public Event MustAddRow As MustAddRowHandler
Delegate type declaration: (which is the prerequisite for the above)
Public Delegate Function MustAddRowHandler(ByVal data As IEnumerable) As IEnumerable
Method 3
As described in the answer of my other post (link), I compiled the C# code into a DLL which I use in my VB Code.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0