Vb.Net to C# : Same event code for Multiple controls

Posted on 2006-03-24
Last Modified: 2008-03-10

Following code handles ItemDrag events for
the ListView controls lvw1, lvw2, lvw3 and lvw4

Private Sub ListView_ItemDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles lvw1.ItemDrag, lvw2.ItemDrag, lvw3.ItemDrag, lvw4.ItemDrag
      sender.SelectedItems(0).Text = "Event Triggered"
End Sub

How to do the same in C# ?

Question by:Shiju Sasidharan
    LVL 96

    Accepted Solution

    Try this:

          this.lvw1.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.ListView_ItemDrag);
          this.lvw2.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.ListView_ItemDrag);
          this.lvw3.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.ListView_ItemDrag);

    private void ListView_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
         ((ListView)sender).SelectedItems(0).Text = "Event Triggered";

    LVL 14

    Author Comment

    by:Shiju Sasidharan
    Thank u Bob

    That was fine :-)
    Thank u


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Need help with a query 3 35
    Email Body 4 31
    custome paging in C# & oracle using inline queries. 12 29
    Detect file exist or not 3 40
    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now