Bound ComboBox resets itself

D

David Cotton

I have 4 combo boxes. They are bound like this:

_dvChassisSC0 = new DataView (_dsChassisSC.Tables[0]);
_dvChassisSC1 = new DataView (_dsChassisSC.Tables[0]);
_dvChassisSC2 = new DataView (_dsChassisSC.Tables[0]);
_dvChassisSC3 = new DataView (_dsChassisSC.Tables[0]);
cbSeg0.DataSource = _dvChassisSC0;
cbSeg0.DisplayMember = "DisplayName";
cbSeg0.ValueMember = "chassis_sc_id";
cbSeg1.DataSource = _dvChassisSC1;
cbSeg1.DisplayMember = "DisplayName";
cbSeg1.ValueMember = "chassis_sc_id";
cbSeg2.DataSource = _dvChassisSC2;
cbSeg2.DisplayMember = "DisplayName";
cbSeg2.ValueMember = "chassis_sc_id";
cbSeg3.DataSource = _dvChassisSC3;
cbSeg3.DisplayMember = "DisplayName";
cbSeg3.ValueMember = "chassis_sc_id";

When the user clicks on the "New" button I set the
SelectedValue = 0 (A non-existant value, also I've tried
setting the SelectedInden to -1) Clearing the value in
the control.

As I trace the code (including some traces into the
disassmbler). The selected index is initially set to -1.
Then I see a call being made to the CurrencyManager being
made. Somewhere in here (gee I wish .Net shipped with the
source like MFC), the SelectedIndex is reset to 0.

Things I've tried:
I've tried creating distinct DataSources along with the
distinct DataViews.
I already mentioned I've tried setting both the
SelectedIndex and SelectedValue.

Does anyone have any ideas that I can try?

Thanks,
Dave
 
K

Kathleen Dollard

David,

Swiped from a piece of code that works. Note that this is for a
DropDownList, which means the textbox is not editable. If the textbox needs
to be editable, I'd suggest you look at setting text = "", perhaps in
addition to setting the selectedindex.

Me.cboApplicationID.SelectedIndex = -1
Me.cboApplicationID.SelectedItem = Nothing


But, I'm not sure that's what the problem is. From your description, are you
creating a new record when the user presses the New button? Is it possible
that you have a default value for the new record? Also, I assume you have a
field named "DisplayName" and one named "chassis_sc_id" in your Chassis
tables? It sounds like the currency manager is trying to set what it
perceives is the correct value.
 
G

Guest

First, to eliminate possible confusion, Kethleen asked if I would be creating a new row in the DataSet bound to the combo box. I am not. The combo box selection is one of many elements that will added to another distinct table.

For those that are curious, I had a RowFilter on the DataView assigned to that combo box. For whatever reason, the currency manager was resetting my selection to a valid selection in harmony with my current filter. Since I must have a filter, my solution was to add a blank "invalid" row.

Personally, this sounds like a bug to me, but then it could be a "feature" LOL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top