开发者

VB Equivalent of C# Event Creation

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 OnMustAddA开发者_开发知识库Row(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.


Like this:

Public Event MustAddRow(data As IEnumerable)


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜