Convert C# to VB online tools not correct

Posted on 2008-11-08
Medium Priority
Last Modified: 2013-12-17
Hi All,

I am trying to convert the C# code below to VB, but the online tools is not converting correctly. Can anyone please help me to get this converted.

this.chkManageDragging.Checked += delegate { this.dragMgr.ListView = this.listView; };
this.chkManageDragging.Unchecked += delegate { this.dragMgr.ListView = null; };
this.chkDragAdorner.Checked += delegate { this.dragMgr.ShowDragAdorner = true; };
this.chkDragAdorner.Unchecked += delegate { this.dragMgr.ShowDragAdorner = false; };
this.sldDragOpacity.ValueChanged += delegate { this.dragMgr.DragAdornerOpacity = this.sldDragOpacity.Value; };
this.chkApplyContStyle.Checked += delegate { this.listView.ItemContainerStyle = this.FindResource( "ItemContStyle" ) as Style; };
this.chkApplyContStyle.Unchecked += delegate { this.listView.ItemContainerStyle = null; };
this.chkSwapDroppedItem.Checked += delegate { this.dragMgr.ProcessDrop += dragMgr_ProcessDrop; };
this.chkSwapDroppedItem.Unchecked += delegate { this.dragMgr.ProcessDrop -= dragMgr_ProcessDrop; };
this.chkShowOtherListView.Checked += delegate { this.listView2.Visibility = Visibility.Visible; };
this.chkShowOtherListView.Unchecked += delegate { this.listView2.Visibility = Visibility.Collapsed; };

Open in new window

Question by:ALawrence007
  • 2
  • 2
  • 2

Expert Comment

ID: 22914447
Not sure of your original code etc but depending on what you want to do, this may be a starter:
Me.chkManageDragging.Checked = Me.dragMgr.ListView Is Me.listView
Me.chkManageDragging.Unchecked = Me.dragMgr.ListView is Nothing
Me.chkDragAdorner.Checked = Me.dragMgr.ShowDragAdorner
Me.chkDragAdorner.Unchecked = Not Me.dragMgr.ShowDragAdorner
Me.sldDragOpacity.ValueChanged = Me.dragMgr.DragAdornerOpacity = Me.sldDragOpacity.Value
Me.chkApplyContStyle.Checked = Me.listView.ItemContainerStyle Is CType(Me.FindResource("ItemContStyle"),Style)

Open in new window

LVL 86

Expert Comment

by:Mike Tomlinson
ID: 22914620
I think those are anonymous delegates?

This part:

    delegate { this.dragMgr.ListView = this.listView; };

Think of it as an un-named method that only exists in memory and can only be accessed by the thing it is assigned to.

At any rate, VB.Net does NOT support anonymous delegates.  The conversion would require you to write SEPARATE actual methods for each piece and use addresof.

Author Comment

ID: 22920653

Thanks for the reply. I get the following Error when I use your code:

'Public Event Checked(sender As Object, e As System.Windows.RoutedEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.    


Can you maybe give me a sample to work with if I need to go that way?

Thanks to both.

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Expert Comment

ID: 22921196
Ah sorry I was not clear that you were using events, wasn't with it!
As Idle_Mind said, you will have to create sepeate Subs for each event/event group.
Unforuntately VB.NET is behind when it comes to delegates!
LVL 86

Accepted Solution

Mike Tomlinson earned 2000 total points
ID: 22922742
Is that a third-party checkbox control?...

Anyhoo, using a Standard .Net CheckBox, I'll illustrate with this:
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler Me.chkManageDragging.CheckedChanged, AddressOf Me.chkManageDragging_CheckedChanged
    End Sub
    Private Sub chkManageDragging_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs
        Me.dragMgr.ListView = Me.listView
    End Sub
End Class

Open in new window


Author Closing Comment

ID: 31514751
Thanks Idle_Mind.

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question