Combobox looses Value when assigning to a typed dataset

  • Thread starter Sergey Poberezovskiy
  • Start date
S

Sergey Poberezovskiy

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;

Help!!!
 
G

Guest

What code are you using to DataBind your controls? Could you post some sample
code?

~~Bonnie
 
S

Sergey Poberezovskiy

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;

-----Original Message-----
What code are you using to DataBind your controls? Could you post some sample
code?

~~Bonnie

Sergey Poberezovskiy said:
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;

Help!!!
.
 
G

Guest

Hmmmm ... OK, let's take another tack ... how and to what values are you
setting the columns in the row?

~~Bonnie



Sergey Poberezovskiy said:
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;

-----Original Message-----
What code are you using to DataBind your controls? Could you post some sample
code?

~~Bonnie

Sergey Poberezovskiy said:
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;

Help!!!
.
 
S

Sergey Poberezovskiy

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?...

-----Original Message-----
Hmmmm ... OK, let's take another tack ... how and to what values are you
setting the columns in the row?

~~Bonnie



Sergey Poberezovskiy said:
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;

-----Original Message-----
What code are you using to DataBind your controls?
Could
you post some sample
code?

~~Bonnie

:

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;

Help!!!

.
.
 
G

Guest

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
 
S

Sergey Poberezovskiy

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.
 

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