all groups > dotnet windows forms > february 2005 >
You're in the

dotnet windows forms

group:

Combobox looses Value when assigning to a typed dataset


Combobox looses Value when assigning to a typed dataset Sergey Poberezovskiy
2/27/2005 2:20:31 PM
dotnet windows forms:
Hi,

This one is rather strange:
I have a form that displays data in a number of controls.
On OK button click event I retrieve the corresponding
record from my typed DataSet:
MyTypedSet.FirstTableRow row = (MyTypedSet.FirstTableRow)
MyTypedSet.FirstTable.Select(filter)[0];

No problems here. But then when I try to assign values to
this row, my checked CheckBox becomes unchecked, my
Comboboxes with DropDownStyle set to DropDown are reset
(SelectedIndex = -1); but Textboxes and Comboboxes with
DDStyle = DropDownList keep their values.
row.AnyColumn = myTextBox.Text;

RE: Combobox looses Value when assigning to a typed dataset Bonnie Berent [C# MVP]
2/27/2005 9:59:01 PM
What code are you using to DataBind your controls? Could you post some sample
code?

~~Bonnie

[quoted text, click to view]
RE: Combobox looses Value when assigning to a typed dataset Sergey Poberezovskiy
2/28/2005 2:45:16 PM
I do not bind them - if I understand the term correctly -
I simply populate them like
cbo.DataSource = new string[]{"one", "two", "three"};

and them set their values from the typed dataset:

MyTypedSet.FirstTableRow row = (MyTypedSet.FirstTableRow)
MyTypedSet.FirstTable.Select(filter)[0];
cbo.Text = row.MyCboField;
chk.Checked = row.MyChkField;


[quoted text, click to view]
RE: Combobox looses Value when assigning to a typed dataset Bonnie Berent [C# MVP]
2/28/2005 3:09:04 PM
Hmmmm ... OK, let's take another tack ... how and to what values are you
setting the columns in the row?

~~Bonnie



[quoted text, click to view]
RE: Combobox looses Value when assigning to a typed dataset Sergey Poberezovskiy
2/28/2005 5:30:18 PM
Bonnie,

As I needed to move forward, I had to declare (string or
bool) variables for each such control and set them to the
controls' values before setting any of the row's
columns... and then reset the controls' values back to
those variables once I populated the row's columns. Not
the quickest and cleanest way though...

string cbo1Value = cbo1.Text;
bool chk1Value = chk1.Checked;
....
row.Field1 = cboValue1; // as soon as this line is
executed the values in DropDown combos and checks are
reset to defaults ?!?!
row.Field2 = chkValue2;
....
cbo1.Text = cbo1Value;
chk1.Checked = chk1Value;

The typed dataset uses the generated code - I use VS2003
Enterprise Architect - not sure what could have gone
wrong?...


[quoted text, click to view]
RE: Combobox looses Value when assigning to a typed dataset Bonnie Berent [C# MVP]
3/1/2005 6:47:07 AM
Sergey,

Well, since you've found a workaround for your problem, I guess it doesn't
matter so much to figure out what was happening. However, I think if you had
used DataBinding, it probably would have gone a lot smoother.

I guess I don't understand why you *didn't* data bind, since you are using a
DataSet. But, anyway, that's just my 2 cents.

~~Bonnie

[quoted text, click to view]
RE: Combobox looses Value when assigning to a typed dataset Sergey Poberezovskiy
3/1/2005 4:35:44 PM
Simple:

I have a ComboBox (DropDownList style) that determines
what record is shown. Once it changes I populate the
other form controls with the values from the
corresponding record(s) of the DataSet.
And after all the changes the user has an option to
either Apply the changes or discard them.

And I have a strong feeling against Data Binding since
early VB versions binding meant that you do not have full
control of what is happening with your data. I still
believe that this is the case with .Net and therefore try
to avoid that as much as possible.

But the question still remains unanswered...

Thanks anyhow for all your time answering this.

[quoted text, click to view]
AddThis Social Bookmark Button