By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,605 Members | 2,012 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,605 IT Pros & Developers. It's quick & easy.

Is this a bug, or do I something Wrong with SelectionChangeCommitted?

P: n/a
Cor
Hi all,

I think I do something wrong, but I don't see what.
I have made a sample.
The sample needs only a form with a combobox and this code.
(I can tell you that it took a long time to see this, but it still can be
that I do something stupid).

When I fill a combobox (1) direct, I get after SelectionChangeCommitted the
previous selected item.
When I fill a combobox (2) using a datatable I get after
SelectionChangeCommitted the selected item (The behaviour that I suspected).

This is the text on MSDN about it,
Occurs when the selected item has changed and that change is committed.

Remarks
You can create a SelectionChangeCommitted event handler to provide special
handling for the ComboBox when the user changes the selected item in the
list.
(That did me doubt if I understood it well).

I am curious if I become crazy?
(I could find nothing about it on MSDN).

Cor

\\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
For i = 10 To 100 Step 10
Me.ComboBox1.Items.Add(i.ToString)
Next
Me.ComboBox1.SelectedIndex = 5
Dim dt As New DataTable
Dim dc As New DataColumn
Dim dr As DataRow
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "i"
dt.Columns.Add(dc)
For i = 1 To 10
dr = dt.NewRow()
dr("i") = (i * 10).ToString
dt.Rows.Add(dr)
Next i
Me.ComboBox2.DisplayMember = "i"
Me.ComboBox2.DataSource = dt
Me.ComboBox2.SelectedIndex = 5
End Sub
Private Sub ComboBox1_SelectionChangeCommitted _
(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
ComboBox1.SelectionChangeCommitted
MessageBox.Show(Me.ComboBox1.Text)
End Sub
Private Sub ComboBox2_SelectionChangeCommitted _
(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
ComboBox2.SelectionChangeCommitted
MessageBox.Show(Me.ComboBox2.Text)
End Sub
///
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Cor
> The sample needs only a form with a combobox and this code.
2 comboboxes
Nov 20 '05 #2

P: n/a
Hi Cor
That is strange.
I edited your code to this
************************
Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As Object, ByVal
e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted

MessageBox.Show("Cbo1 - Change Committed:" & Me.ComboBox1.Text)

End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

MessageBox.Show("Cbo1 - Index changed: " & Me.ComboBox1.Text)

End Sub

Private Sub ComboBox2_SelectionChangeCommitted(ByVal sender As Object, ByVal
e As System.EventArgs) Handles ComboBox2.SelectionChangeCommitted

MessageBox.Show("Cbo2 - Change Committed: " & Me.ComboBox2.Text)

End Sub

Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ComboBox2.SelectedIndexChanged

MessageBox.Show("Cbo2 - Index changed: " & Me.ComboBox2.Text)

End Sub

**********************************

And it seems (like you said) that the ChangeCommitted event appears before
the value actually changes when the combo is filled directly. But it works
well if you use datarows (like you said)

Then I looked in the code and the only difference I could tell was the
..Displaymember so I tried this (Just a guess)

*********************

Me.ComboBox1.DisplayMember = Me.ComboBox1.Items(0)

**********************

And then it worked fine

I am puzzled

Jan


"Cor" <no*@non.com> skrev i en meddelelse
news:uW**************@TK2MSFTNGP11.phx.gbl...
The sample needs only a form with a combobox and this code.

2 comboboxes

Nov 20 '05 #3

P: n/a
Cor
Hi Jan,

This is a nice workaround yes.
*********************

Me.ComboBox1.DisplayMember = Me.ComboBox1.Items(0)

**********************

I did make datatables instead.

I think I bring it back again to this.

Cor
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.