Combo Box Binding Theory Gap

  • Thread starter Thread starter Richard Myers
  • Start date Start date
R

Richard Myers

Hello.

Im stumped over the following behaviour.

I want to trigger an update of some related form fields when a sales
territory combo is updated. Ive found that if the selectedindex already = 0
and i .selectedindex = 0 then the selectedvalue is not updated. I assume
selectedvalue is only updated OnSelectedIndexChanged not just when this
property is set?

So my current work around is setting the .selctedindex = -1 then the
following staement .selectedindex =0.
However this is stupid code. So then i thought i'd set the datasource to
nothing as below.
With Me.cboTerritory
.DataSource = Nothing
.DataSource = _validCustomerTerritories.SalesTerritory
.ValueMember = "SalesTerritoryId"
.DisplayMember = "TerritoryName"
_bindingTerritory = False
If .Items.Count > 0 Then .SelectedIndex = 0
End With

However, and this relates to my question, in doing this .selectedindex=0 is
never fired because .items.count is never > 0, even though
_validCustomerTerritories.SalesTerritory has more than 15 items in it?

If i take out out .Datasource = Nothing then .Items.Count = 15 but then as
above .SelectedIndex = 0 doesn't trigger the update because .SelectedIndex
ws already 0. I dont understand why setting the .Datasource to "nothng"
before setting it too "something with a positive count" screws up the .items
collection count?

I can work around it with an extra statement or but i dont think i should
have too.
Any ideas?

TIA
Richard
 
Normally, I add a first item [Please Select Territory] or something similar,
and validation takes care of not allowing the default forcing the user to
make a selection.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
Hi Terry,

Thanks. I do that with web applications but for some reason have a built in
bias against it in Windows apps.
Can you confirm that selectedValue is set only when selectedindex changes
and not just when the .selectedindex property is set?

Thanks
Richard


One Handed Man ( OHM - Terry Burns ) said:
Normally, I add a first item [Please Select Territory] or something similar,
and validation takes care of not allowing the default forcing the user to
make a selection.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

Richard Myers said:
Hello.

Im stumped over the following behaviour.

I want to trigger an update of some related form fields when a sales
territory combo is updated. Ive found that if the selectedindex already
=
0
and i .selectedindex = 0 then the selectedvalue is not updated. I assume
selectedvalue is only updated OnSelectedIndexChanged not just when this
property is set?

So my current work around is setting the .selctedindex = -1 then the
following staement .selectedindex =0.
However this is stupid code. So then i thought i'd set the datasource to
nothing as below.
With Me.cboTerritory
.DataSource = Nothing
.DataSource = _validCustomerTerritories.SalesTerritory
.ValueMember = "SalesTerritoryId"
.DisplayMember = "TerritoryName"
_bindingTerritory = False
If .Items.Count > 0 Then .SelectedIndex = 0
End With

However, and this relates to my question, in doing this .selectedindex=0 is
never fired because .items.count is never > 0, even though
_validCustomerTerritories.SalesTerritory has more than 15 items in it?

If i take out out .Datasource = Nothing then .Items.Count = 15 but then as
above .SelectedIndex = 0 doesn't trigger the update because ..SelectedIndex
ws already 0. I dont understand why setting the .Datasource to "nothng"
before setting it too "something with a positive count" screws up the .items
collection count?

I can work around it with an extra statement or but i dont think i should
have too.
Any ideas?

TIA
Richard
 
Forget about that question. Its just me being lazy. I can confirm this for
myself.
 
Sorry, I only just saw your reply and question this morning, as you request,
I will allow you to confirm this for yourself.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
Back
Top