Link to home
Create AccountLog in
Avatar of Marianne VAN WYK
Marianne VAN WYKFlag for South Africa

asked on

vb.net code not working after c# conversion (RaisEvent)

Hi,
I've converted c# code to vb.net but for some reason it doesn't work.Not sure what I missed.
I get an error that says.
'Public Event PositionChanged(sender As Object, e As System.EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event."
can someone please help me.

This is in an DevExpress.XtraReport Class
Regards
Will
C# Code:
 
public partial class XtraReportMailingLabels: DevExpress.XtraReports.UI.XtraReport {
        int skipnumber;
        const int skip = 11;
        public XtraReportMailingLabels() {
            InitializeComponent();
            skipnumber = skip;
        }
        private void xrPanel1_BeforePrint (object sender, System.Drawing.Printing.PrintEventArgs e) {
            if(skipnumber >= 0 ) {
                e.Cancel = true;
            }
        }
 
        private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
            if(skipnumber > 0) {
                DevExpress.Data.Browsing.DataBrowser browser = this.fDataContext[this.DataSource, this.DataMember];
                browser.PositionChanged += new EventHandler(browser_PositionChanged);
            }
            skipnumber--;
        }
        bool stop = false;
        void browser_PositionChanged(object sender, EventArgs e) {
            ((DevExpress.Data.Browsing.ListBrowser)(sender)).PositionChanged -= browser_PositionChanged;
            if(!stop)
            ((DevExpress.Data.Browsing.ListBrowser)(sender)).Position =0;
        if(skipnumber <= 0) {
            stop = true;
        }
        }
 
    }
 
 
VB CODE:
 
Public Class XtraReportMailingLabels
    Inherits DevExpress.XtraReports.UI.XtraReport
    Private skipnumber As Integer
    Const skip As Integer = 11
    Public Sub New()
        InitializeComponent()
        skipnumber = skip
    End Sub
    Private Sub xrPanel1_BeforePrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles XrPanel1.BeforePrint
        If skipnumber >= 0 Then
            e.Cancel = True
        End If
    End Sub
 
    Private Sub Detail_BeforePrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles Detail.BeforePrint
        If skipnumber > 0 Then
            Dim browser As DevExpress.Data.Browsing.DataBrowser = Me.fDataContext(Me.DataSource, Me.DataMember)
            AddHandler browser.PositionChanged, AddressOf browser_PositionChanged
        End If
        skipnumber -= 1
    End Sub
    Private [stop] As Boolean = False
   
    Private Sub browser_PositionChanged(ByVal sender As Object, ByVal e As EventArgs)
        DirectCast((sender), DevExpress.Data.Browsing.ListBrowser).PositionChanged -= browser_PositionChanged()
        If Not [stop] Then
            DirectCast((sender), DevExpress.Data.Browsing.ListBrowser).Position = 0
        End If
        If skipnumber <= 0 Then
            [stop] = True
        End If
    End Sub
 
End Class

Open in new window

Avatar of sunithnair
sunithnair

You VB code should be something like this
Public Class XtraReportMailingLabels
    Inherits DevExpress.XtraReports.UI.XtraReport
    Private skipnumber As Integer
    Const skip As Integer = 11
    Public Sub New()
        InitializeComponent()
        skipnumber = skip
    End Sub
    Private Sub xrPanel1_BeforePrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles XrPanel1.BeforePrint
        If skipnumber >= 0 Then
            e.Cancel = True
        End If
    End Sub
 
    Private Sub Detail_BeforePrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles Detail.BeforePrint
        If skipnumber > 0 Then
            Dim browser As DevExpress.Data.Browsing.DataBrowser = Me.fDataContext(Me.DataSource, Me.DataMember)
            AddHandler browser.PositionChanged, AddressOf browser_PositionChanged
        End If
        skipnumber -= 1
    End Sub
    Private [stop] As Boolean = False
   
    Private Sub browser_PositionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles broswer.PositionChanged
        DirectCast((sender), DevExpress.Data.Browsing.ListBrowser).PositionChanged -= browser_PositionChanged()
        If Not [stop] Then
            DirectCast((sender), DevExpress.Data.Browsing.ListBrowser).Position = 0
        End If
        If skipnumber <= 0 Then
            [stop] = True
        End If
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of pivar
pivar
Flag of Sweden image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer