我遇到一個問題,我在網上找到的vb.net代碼轉換爲C#。試圖將VB.Net轉換爲C#
vb.net
Protected Overridable Sub OnRowClicked(ByVal e As GridViewRowClickedEventArgs)
'raise the RowClicked event
RaiseEvent RowClicked(Me, e)
End Sub
'setup our EventHandler for RowClicked
Public Custom Event RowClicked As EventHandler(Of GridViewRowClickedEventArgs)
AddHandler(ByVal value As EventHandler(Of GridViewRowClickedEventArgs))
Events.AddHandler(RowClickedEventKey, value)
End AddHandler
RemoveHandler(ByVal value As EventHandler(Of GridViewRowClickedEventArgs))
Events.RemoveHandler(RowClickedEventKey, value)
End RemoveHandler
RaiseEvent(ByVal sender As Object, ByVal e As GridViewRowClickedEventArgs)
Dim ev As EventHandler(Of GridViewRowClickedEventArgs) = TryCast(Events(RowClickedEventKey), EventHandler(Of GridViewRowClickedEventArgs))
If Not IsNothing(ev) Then
ev(sender, e)
End If
End RaiseEvent
End Event
C#
protected virtual void OnRowClicked(GridViewRowClickedEventArgs e)
{
//raise the RowClicked event
if (RowClicked != null)
{
RowClicked(this, e);
}
}
//setup our EventHandler for RowClicked
public event EventHandler<GridViewRowClickedEventArgs> RowClicked
{
add { Events.AddHandler(RowClickedEventKey, value); }
remove { Events.RemoveHandler(RowClickedEventKey, value); }
}
我曾經在網絡上的代碼轉換器。問題是在線
//raise the RowClicked event
if (RowClicked != null)
{
RowClicked(this, e);
}
我得到的錯誤是:「RowClickGridView.RowClicked」事件只能出現在的+ =或左邊 - =
任何想法?
不遵守?但我需要那個事件處理程序。 – MindGame 2012-03-19 16:47:16