rwallacej
asked on
VB.net - SelectionChangeCommitted event problem
I've a problem with the SelectionChangeCommitted event
The event is triggered when user does change, but when checking the ComboBox.text after even, the text value is the same as previous - it doesn't change.
I'm using SelectionChangeCommitted so event is only triggered when user does change to combo box, and not when any code changes the combo
Came across this http://weblogs.asp.net/grobinson/archive/2005/09/21/425711.aspx but not really sure what its saying to do
Thanks
The event is triggered when user does change, but when checking the ComboBox.text after even, the text value is the same as previous - it doesn't change.
I'm using SelectionChangeCommitted so event is only triggered when user does change to combo box, and not when any code changes the combo
Came across this http://weblogs.asp.net/grobinson/archive/2005/09/21/425711.aspx but not really sure what its saying to do
Thanks
ASKER
Private Sub ComboBox_MP_SelectionChang eCommitted (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox_MP.SelectionChang eCommitted
MessageBox.Show("THE NEW VALUE IS: " & ComboBox_MP.Text)
End Sub
displays
1) THE NEW VALUE IS: [the original value]
2) the combo box the changes
the messagebox appears before the combobox changes
MessageBox.Show("THE NEW VALUE IS: " & ComboBox_MP.Text)
End Sub
displays
1) THE NEW VALUE IS: [the original value]
2) the combo box the changes
the messagebox appears before the combobox changes
You'll want to use:
MessageBox.Show("THE NEW VALUE IS: " & ComboBox_MP.SelectedValue)
(or .SelectedText)
MessageBox.Show("THE NEW VALUE IS: " & ComboBox_MP.SelectedValue)
(or .SelectedText)
ASKER
still the same :-(
ASKER
form2.designer.vb
<Global.Microsoft.VisualBa sic.Compil erServices .DesignerG enerated() > _
Partial Class Form2
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.Debugg erNonUserC ode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.Debugg erStepThro ugh()> _
Private Sub InitializeComponent()
Me.ComboBox_MP = New System.Windows.Forms.Combo Box
Me.SuspendLayout()
'
'ComboBox_MP
'
Me.ComboBox_MP.FormattingE nabled = True
Me.ComboBox_MP.Items.AddRa nge(New Object() {"None", "Motor driven", "Turbine driven"})
Me.ComboBox_MP.Location = New System.Drawing.Point(12, 12)
Me.ComboBox_MP.Name = "ComboBox_MP"
Me.ComboBox_MP.Size = New System.Drawing.Size(109, 21)
Me.ComboBox_MP.TabIndex = 6
'
'Form2
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoS caleMode.F ont
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.ComboBo x_MP)
Me.Name = "Form2"
Me.Text = "Form2"
Me.ResumeLayout(False)
End Sub
Friend WithEvents ComboBox_MP As System.Windows.Forms.Combo Box
End Class
<Global.Microsoft.VisualBa
Partial Class Form2
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.Debugg
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.Debugg
Private Sub InitializeComponent()
Me.ComboBox_MP = New System.Windows.Forms.Combo
Me.SuspendLayout()
'
'ComboBox_MP
'
Me.ComboBox_MP.FormattingE
Me.ComboBox_MP.Items.AddRa
Me.ComboBox_MP.Location = New System.Drawing.Point(12, 12)
Me.ComboBox_MP.Name = "ComboBox_MP"
Me.ComboBox_MP.Size = New System.Drawing.Size(109, 21)
Me.ComboBox_MP.TabIndex = 6
'
'Form2
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!,
Me.AutoScaleMode = System.Windows.Forms.AutoS
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.ComboBo
Me.Name = "Form2"
Me.Text = "Form2"
Me.ResumeLayout(False)
End Sub
Friend WithEvents ComboBox_MP As System.Windows.Forms.Combo
End Class
ASKER
Public Class Form2
Private Sub ComboBox_MP_SelectionChang eCommitted (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox_MP.SelectionChang eCommitted
MessageBox.Show("THE NEW VALUE IS: " & ComboBox_MP.SelectedText)
End Sub
End Class
Private Sub ComboBox_MP_SelectionChang
MessageBox.Show("THE NEW VALUE IS: " & ComboBox_MP.SelectedText)
End Sub
End Class
Did you try selectedValue?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yes, selectedvalue always gives "" (blank)
ASKER
MessageBox.Show(ComboBox_M P.Items.It em(ComboBo x_MP.Selec tedIndex))
works
works
Odd - but glad it does! :^)
What's in the event code now?
I'm using this currently in a project I'm working on and don't see that behavior...
~sirbounty