We help IT Professionals succeed at work.

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

Shiju Sasidharan
on
Medium Priority
445 Views
Last Modified: 2008-03-10
Hi

Following Vb.net 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# ?

Thanks
Shiju
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
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";
}

Bob

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Shiju SasidharanSenior IT Developer

Author

Commented:
Thank u Bob

That was fine :-)
Thank u

Shiju
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.