How to auto-update field w/ dropdown selection

slybitz

Member
Joined
Aug 16, 2005
Messages
9
Programming Experience
Beginner
So I have a dropdown box that I have filled with two values: AFD, CFD. All I'm trying to do is to get a text box (txtComp) to change its value to that of a dropdown list box (cmbCompany) selection. For some reason I cannot get the text box to reflect this data. I can't even get the text box to just say "CFD" like below with an index change in the dropdown box (which is initially set to "AFD" onload). When I run the debugger and change the dropdown box's values it never recognizes that the "cmbCompany_SelectedIndexChanged" sub (below) is never even initiated. Am I missing something? What all do I need to do to make the txtComp value change to that of the dropdown box on an index change? Thanks for your help!

VB.NET:
[FONT=Courier New][SIZE=2][FONT='Courier New']    [COLOR=blue][COLOR=blue]Public[/COLOR][/COLOR] [COLOR=blue][COLOR=blue]Sub[/COLOR][/COLOR] cmbCompany_SelectedIndexChanged([COLOR=blue][COLOR=blue]ByVal[/COLOR][/COLOR] sender [COLOR=blue][COLOR=blue]As[/COLOR][/COLOR] [COLOR=blue][COLOR=blue]Object[/COLOR][/COLOR], [COLOR=blue][COLOR=blue]ByVal[/COLOR][/COLOR] e [COLOR=blue][COLOR=blue]As[/COLOR][/COLOR] System.EventArgs) [COLOR=blue][COLOR=blue]Handles [/COLOR][/COLOR]cmbCompany.SelectedIndexChanged[/FONT][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][FONT='Courier New']        [COLOR=blue][COLOR=blue]Me[/COLOR][/COLOR].txtComp.Text = "CFD"[/FONT][/SIZE][/FONT]
[FONT=Courier New][SIZE=2][FONT='Courier New']    [COLOR=blue][COLOR=blue]End[/COLOR][/COLOR] [COLOR=blue][COLOR=blue]Sub[/COLOR][/COLOR][/FONT][/SIZE][/FONT]
 
So your saying that the selected index change event isn't firing? Thats odd, i'm pretty sure it is. I litererally just tried this and it works fine. Just out if interest why is the event handler public, they are normally private?
 
I got the SelectedIndexChanged to fire but my Me.txtComp.Text won't update with the correct value. No matter if I change the dropdownlist to CFD my code is filling
Me
.txtComp.Text value with AFD always. Here's my code:

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Page_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load
[/SIZE][SIZE=2][COLOR=#008000]'0000000007
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'Me.txtComp.Text = cmbCompany.SelectedItem.Value
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].cmbCompany.Items.Clear()
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] company() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = {"AFD", "CFD"}
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].cmbCompany.DataSource = company
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].cmbCompany.DataBind()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] cmbCompany_SelectedIndexChanged([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] cmbCompany.SelectedIndexChanged
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].cmbCompany.SelectedValue.Equals([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].cmbCompany.SelectedItem.Value)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] company [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].cmbCompany.SelectedItem.Value [/SIZE][SIZE=2][COLOR=#0000ff]Is[/COLOR][/SIZE][SIZE=2] "CFD" [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtComp.Text = "CFD"
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtComp.Text = "AFD"
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2] 
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]
 
Back
Top