[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Vb.net two dropdown one function

Posted on 2014-08-27
4
Medium Priority
?
209 Views
Last Modified: 2014-09-11
Protected Sub ddlManagers_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlManagersTop.SelectedIndexChanged, ddlManagersBottom.SelectedIndexChanged

dosomething(ddlManagersTop.SelectedItem.Text)

 End Sub

I have one function for two dropdown selected index changed events,
Now above code workd only if the selection in Top dropdown changes but not working for the botton drop down.
How can I make it work for both the dropdowns/
0
Comment
Question by:Angela4eva
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 40289224
Don't refer to ddlManagersTop directly within this handler. The first parameter to any event handler is the actual object (in this case control) that raised the event. Use that:

e.g.

Protected Sub ddlManagers_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlManagersTop.SelectedIndexChanged, ddlManagersBottom.SelectedIndexChanged

  Dim ddl As DropDownList = DirectCast(sender, DropDownList)  ' Cast the "sender" to a DropDownList
  
  dosomething(ddl.SelectedItem.Text)

End Sub

Open in new window

0
 
LVL 15

Expert Comment

by:ChloesDad
ID: 40289226
Do both dropdowns set the dropdownstyle to dropdownList. If the user can type free text into the box then sometimes the index does not change and hence the event does not trigger.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40289235
I'm guessing the above should be ComboBox rather than DropDownList--it's been so long since I've done WinForms. The concept is the same; change the class accordingly.   = )
0
 
LVL 13

Expert Comment

by:ktaczala
ID: 40289241
add
Dim ddl As <your control type> = DirectCast(sender, <your control type> )
dosomething(ddl.selecteditem.text)
<your control type> is whatever control you want/need. i.e. button, combobox, etc.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Loops Section Overview

834 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