I have a windows forms that shows only one record at a time.

The user selects the record he want via a combo box. Everything works fine
for the first selection, however the textboxes do not automatically update
their values when the combo box changes values.

The textboxes are bound to a dataset. Here is and an example of what the
databinding lookes like in designer:

Text: DsEventPerson1 - tblSubject.FirstName

When the user selects a new row in the combo box, the DsEventPerson1 is
cleared and refilled. What must I do to get the textboxes to show the
correct values for each record selected?

--
wr

RE: Databinding to Textboxes by WhiskyRomeo

WhiskyRomeo
Sat Feb 19 10:33:03 CST 2005

Well no help on this one?

The approach I took was to drop binding, clear and refill the dataset, and
re-add the bindings.

wr

"WhiskyRomeo" wrote:

> I have a windows forms that shows only one record at a time.
>
> The user selects the record he want via a combo box. Everything works fine
> for the first selection, however the textboxes do not automatically update
> their values when the combo box changes values.
>
> The textboxes are bound to a dataset. Here is and an example of what the
> databinding lookes like in designer:
>
> Text: DsEventPerson1 - tblSubject.FirstName
>
> When the user selects a new row in the combo box, the DsEventPerson1 is
> cleared and refilled. What must I do to get the textboxes to show the
> correct values for each record selected?
>
> --
> wr

RE: Databinding to Textboxes by BonnieBerentCMVP

BonnieBerentCMVP
Sat Feb 19 23:41:10 CST 2005

What code do you have in your ComboBox's .SelectedIndexChanged Event Handler?
You need to move the BindingContext Position in order for the correct row to
show up in the bound TextBoxes.

~~Bonnie

"WhiskyRomeo" wrote:

> I have a windows forms that shows only one record at a time.
>
> The user selects the record he want via a combo box. Everything works fine
> for the first selection, however the textboxes do not automatically update
> their values when the combo box changes values.
>
> The textboxes are bound to a dataset. Here is and an example of what the
> databinding lookes like in designer:
>
> Text: DsEventPerson1 - tblSubject.FirstName
>
> When the user selects a new row in the combo box, the DsEventPerson1 is
> cleared and refilled. What must I do to get the textboxes to show the
> correct values for each record selected?
>
> --
> wr

RE: Databinding to Textboxes by WhiskyRomeo

WhiskyRomeo
Sun Feb 20 09:45:04 CST 2005

Since each event can have anywhere from 30 to 800 grads in them and since the
user is only interested in one or two grads when they use this form, each
selection in the combo box clears the dataset the textboxes are bound to and
retrieves exactly one record from the database.

If, instead, I retrieved the entire event I would have worked with the
BindingContext Position. However, that isn't applicable in this case, since
there is only one record.

wr


"Bonnie Berent [C# MVP]" wrote:

> What code do you have in your ComboBox's .SelectedIndexChanged Event Handler?
> You need to move the BindingContext Position in order for the correct row to
> show up in the bound TextBoxes.
>
> ~~Bonnie
>
> "WhiskyRomeo" wrote:
>
> > I have a windows forms that shows only one record at a time.
> >
> > The user selects the record he want via a combo box. Everything works fine
> > for the first selection, however the textboxes do not automatically update
> > their values when the combo box changes values.
> >
> > The textboxes are bound to a dataset. Here is and an example of what the
> > databinding lookes like in designer:
> >
> > Text: DsEventPerson1 - tblSubject.FirstName
> >
> > When the user selects a new row in the combo box, the DsEventPerson1 is
> > cleared and refilled. What must I do to get the textboxes to show the
> > correct values for each record selected?
> >
> > --
> > wr

RE: Databinding to Textboxes by BonnieBerentCMVP

BonnieBerentCMVP
Sun Feb 20 10:31:05 CST 2005

Well, then, I guess the solution you already found is probably the best one
to use (dropping the bindings and then adding them back).

You might want to consider adding Bind, UnBind and ReBind methods to your
base classes (along with your own IBind interface). This makes it much easier
when you have a lot of controls on your form, because those methods, at a
Form level would call the methods in it's Controls collection for those
controls that implement the IBind interface. You wouldn't have to do it for
each TextBox (or whatever) yourself, you'd simply issue the Form UnBind and
ReBind, and it would handle it all for you.

~~Bonnie

"WhiskyRomeo" wrote:

> Since each event can have anywhere from 30 to 800 grads in them and since the
> user is only interested in one or two grads when they use this form, each
> selection in the combo box clears the dataset the textboxes are bound to and
> retrieves exactly one record from the database.
>
> If, instead, I retrieved the entire event I would have worked with the
> BindingContext Position. However, that isn't applicable in this case, since
> there is only one record.
>
> wr
>
>
> "Bonnie Berent [C# MVP]" wrote:
>
> > What code do you have in your ComboBox's .SelectedIndexChanged Event Handler?
> > You need to move the BindingContext Position in order for the correct row to
> > show up in the bound TextBoxes.
> >
> > ~~Bonnie
> >
> > "WhiskyRomeo" wrote:
> >
> > > I have a windows forms that shows only one record at a time.
> > >
> > > The user selects the record he want via a combo box. Everything works fine
> > > for the first selection, however the textboxes do not automatically update
> > > their values when the combo box changes values.
> > >
> > > The textboxes are bound to a dataset. Here is and an example of what the
> > > databinding lookes like in designer:
> > >
> > > Text: DsEventPerson1 - tblSubject.FirstName
> > >
> > > When the user selects a new row in the combo box, the DsEventPerson1 is
> > > cleared and refilled. What must I do to get the textboxes to show the
> > > correct values for each record selected?
> > >
> > > --
> > > wr

RE: Databinding to Textboxes by BonnieBerentCMVP

BonnieBerentCMVP
Sun Feb 20 10:35:06 CST 2005

Actually, though, I just had another thought. If you're simply clearing the
DataSet, that shouldn't mess up your binding (although I haven't messed with
it) ... how are you adding the new row back in?

~~Bonnie


"WhiskyRomeo" wrote:

> Since each event can have anywhere from 30 to 800 grads in them and since the
> user is only interested in one or two grads when they use this form, each
> selection in the combo box clears the dataset the textboxes are bound to and
> retrieves exactly one record from the database.
>
> If, instead, I retrieved the entire event I would have worked with the
> BindingContext Position. However, that isn't applicable in this case, since
> there is only one record.
>
> wr
>
>
> "Bonnie Berent [C# MVP]" wrote:
>
> > What code do you have in your ComboBox's .SelectedIndexChanged Event Handler?
> > You need to move the BindingContext Position in order for the correct row to
> > show up in the bound TextBoxes.
> >
> > ~~Bonnie
> >
> > "WhiskyRomeo" wrote:
> >
> > > I have a windows forms that shows only one record at a time.
> > >
> > > The user selects the record he want via a combo box. Everything works fine
> > > for the first selection, however the textboxes do not automatically update
> > > their values when the combo box changes values.
> > >
> > > The textboxes are bound to a dataset. Here is and an example of what the
> > > databinding lookes like in designer:
> > >
> > > Text: DsEventPerson1 - tblSubject.FirstName
> > >
> > > When the user selects a new row in the combo box, the DsEventPerson1 is
> > > cleared and refilled. What must I do to get the textboxes to show the
> > > correct values for each record selected?
> > >
> > > --
> > > wr

RE: Databinding to Textboxes by BonnieBerentCMVP

BonnieBerentCMVP
Sun Feb 20 11:01:02 CST 2005

OK, I've played around with it a bit, just to be sure. This should work, so
you're missing something somewhere. You showed how the text box databinding
looks in the IDE, but how does it actually look in the code? (And also, my
other question is still pertinent ... how are you adding in the new row?)

~~Bonnie


"WhiskyRomeo" wrote:

> Since each event can have anywhere from 30 to 800 grads in them and since the
> user is only interested in one or two grads when they use this form, each
> selection in the combo box clears the dataset the textboxes are bound to and
> retrieves exactly one record from the database.
>
> If, instead, I retrieved the entire event I would have worked with the
> BindingContext Position. However, that isn't applicable in this case, since
> there is only one record.
>
> wr
>
>
> "Bonnie Berent [C# MVP]" wrote:
>
> > What code do you have in your ComboBox's .SelectedIndexChanged Event Handler?
> > You need to move the BindingContext Position in order for the correct row to
> > show up in the bound TextBoxes.
> >
> > ~~Bonnie
> >
> > "WhiskyRomeo" wrote:
> >
> > > I have a windows forms that shows only one record at a time.
> > >
> > > The user selects the record he want via a combo box. Everything works fine
> > > for the first selection, however the textboxes do not automatically update
> > > their values when the combo box changes values.
> > >
> > > The textboxes are bound to a dataset. Here is and an example of what the
> > > databinding lookes like in designer:
> > >
> > > Text: DsEventPerson1 - tblSubject.FirstName
> > >
> > > When the user selects a new row in the combo box, the DsEventPerson1 is
> > > cleared and refilled. What must I do to get the textboxes to show the
> > > correct values for each record selected?
> > >
> > > --
> > > wr

RE: Databinding to Textboxes by WhiskyRomeo

WhiskyRomeo
Sun Feb 20 11:03:03 CST 2005

I simply clear the dataset and refill it. Here is the code that does that.
The only change that makes this work is the clear and adding of binding
before and after the merge.

Sub FillEventPerson()

DsEventPerson1.Clear()
With Me
.tbFName.DataBindings.Clear()
.tbLName.DataBindings.Clear()
.tbEmail.DataBindings.Clear()
.tbNotes.DataBindings.Clear()
End With

DsEventPerson1.Merge(wsCommon.GetSpecificPerson(cmbSubject.Value))

With Me
.tbFName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "FirstName")
.tbLName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "LastName")
.tbEmail.DataBindings.Add("Text", DsEventPerson1.tblSubject, "Email")
.tbNotes.DataBindings.Add("Text", DsEventPerson1.tblSubject, "Notes")
End With
'rest of this code does not apply to this problem
RowCountB = 0
CurrentRowB = 0
Dim ds As New wsOrgEvent.dsSubjectFoto
ds.Merge(wsCommon.GetSpecificFotos(cmbSubject.Value))
dtFotosB = ds.tblSubjectFoto
RowCountB = dtFotosB.Rows.Count
Call InitializeDisplay()
ds = Nothing
End Sub



"Bonnie Berent [C# MVP]" wrote:

> Actually, though, I just had another thought. If you're simply clearing the
> DataSet, that shouldn't mess up your binding (although I haven't messed with
> it) ... how are you adding the new row back in?
>
> ~~Bonnie
>
>
> "WhiskyRomeo" wrote:
>
> > Since each event can have anywhere from 30 to 800 grads in them and since the
> > user is only interested in one or two grads when they use this form, each
> > selection in the combo box clears the dataset the textboxes are bound to and
> > retrieves exactly one record from the database.
> >
> > If, instead, I retrieved the entire event I would have worked with the
> > BindingContext Position. However, that isn't applicable in this case, since
> > there is only one record.
> >
> > wr
> >
> >
> > "Bonnie Berent [C# MVP]" wrote:
> >
> > > What code do you have in your ComboBox's .SelectedIndexChanged Event Handler?
> > > You need to move the BindingContext Position in order for the correct row to
> > > show up in the bound TextBoxes.
> > >
> > > ~~Bonnie
> > >
> > > "WhiskyRomeo" wrote:
> > >
> > > > I have a windows forms that shows only one record at a time.
> > > >
> > > > The user selects the record he want via a combo box. Everything works fine
> > > > for the first selection, however the textboxes do not automatically update
> > > > their values when the combo box changes values.
> > > >
> > > > The textboxes are bound to a dataset. Here is and an example of what the
> > > > databinding lookes like in designer:
> > > >
> > > > Text: DsEventPerson1 - tblSubject.FirstName
> > > >
> > > > When the user selects a new row in the combo box, the DsEventPerson1 is
> > > > cleared and refilled. What must I do to get the textboxes to show the
> > > > correct values for each record selected?
> > > >
> > > > --
> > > > wr

RE: Databinding to Textboxes by BonnieBerentCMVP

BonnieBerentCMVP
Sun Feb 20 11:29:07 CST 2005

I simply added a new Row to my DataTable after clearing it. Since you're
attempting to use the .Merge() method, could you tell me what your
wsCommon.GetSpecificPerson(cmbSubject.Value) returns? Rows? DataSet?
DataTable? I suspect the problem probably lies here somewhere.

~~Bonnie



"WhiskyRomeo" wrote:

> I simply clear the dataset and refill it. Here is the code that does that.
> The only change that makes this work is the clear and adding of binding
> before and after the merge.
>
> Sub FillEventPerson()
>
> DsEventPerson1.Clear()
> With Me
> .tbFName.DataBindings.Clear()
> .tbLName.DataBindings.Clear()
> .tbEmail.DataBindings.Clear()
> .tbNotes.DataBindings.Clear()
> End With
>
> DsEventPerson1.Merge(wsCommon.GetSpecificPerson(cmbSubject.Value))
>
> With Me
> .tbFName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "FirstName")
> .tbLName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "LastName")
> .tbEmail.DataBindings.Add("Text", DsEventPerson1.tblSubject, "Email")
> .tbNotes.DataBindings.Add("Text", DsEventPerson1.tblSubject, "Notes")
> End With
> 'rest of this code does not apply to this problem
> RowCountB = 0
> CurrentRowB = 0
> Dim ds As New wsOrgEvent.dsSubjectFoto
> ds.Merge(wsCommon.GetSpecificFotos(cmbSubject.Value))
> dtFotosB = ds.tblSubjectFoto
> RowCountB = dtFotosB.Rows.Count
> Call InitializeDisplay()
> ds = Nothing
> End Sub
>
>
>
> "Bonnie Berent [C# MVP]" wrote:
>
> > Actually, though, I just had another thought. If you're simply clearing the
> > DataSet, that shouldn't mess up your binding (although I haven't messed with
> > it) ... how are you adding the new row back in?
> >
> > ~~Bonnie
> >
> >
> > "WhiskyRomeo" wrote:
> >
> > > Since each event can have anywhere from 30 to 800 grads in them and since the
> > > user is only interested in one or two grads when they use this form, each
> > > selection in the combo box clears the dataset the textboxes are bound to and
> > > retrieves exactly one record from the database.
> > >
> > > If, instead, I retrieved the entire event I would have worked with the
> > > BindingContext Position. However, that isn't applicable in this case, since
> > > there is only one record.
> > >
> > > wr
> > >
> > >
> > > "Bonnie Berent [C# MVP]" wrote:
> > >
> > > > What code do you have in your ComboBox's .SelectedIndexChanged Event Handler?
> > > > You need to move the BindingContext Position in order for the correct row to
> > > > show up in the bound TextBoxes.
> > > >
> > > > ~~Bonnie
> > > >
> > > > "WhiskyRomeo" wrote:
> > > >
> > > > > I have a windows forms that shows only one record at a time.
> > > > >
> > > > > The user selects the record he want via a combo box. Everything works fine
> > > > > for the first selection, however the textboxes do not automatically update
> > > > > their values when the combo box changes values.
> > > > >
> > > > > The textboxes are bound to a dataset. Here is and an example of what the
> > > > > databinding lookes like in designer:
> > > > >
> > > > > Text: DsEventPerson1 - tblSubject.FirstName
> > > > >
> > > > > When the user selects a new row in the combo box, the DsEventPerson1 is
> > > > > cleared and refilled. What must I do to get the textboxes to show the
> > > > > correct values for each record selected?
> > > > >
> > > > > --
> > > > > wr

RE: Databinding to Textboxes by WhiskyRomeo

WhiskyRomeo
Sun Feb 20 12:03:01 CST 2005

it returns a dataset. Here is the code for that:

<WebMethod()> Public Function GetSpecificPerson(ByVal intPerson_ID As Int32)
As dsEventPerson
Dim ds As New dsEventPerson
'Get Subjects
daSpecificPerson.SelectCommand.Parameters("@Person_ID").Value = intPerson_ID
daSpecificPerson.Fill(ds, "tblSubject")

'Get Subject Addresses
daSpecificAddress.SelectCommand.Parameters("@Person_ID").Value = intPerson_ID
daSpecificAddress.Fill(ds, "tblSubjectAddress")

'Get Associates
daSpecificAssociate.SelectCommand.Parameters("@AssociatedSubject_ID").Value
= intPerson_ID
daSpecificAssociate.Fill(ds, "tblAssociate")

'Get Associate Addresses
daSpecificAssociateAddress.SelectCommand.Parameters("@AssociatedSubject_ID").Value = intPerson_ID
daSpecificAssociateAddress.Fill(ds, "tblAssociateAddress")
Return ds
End Function

wr

"Bonnie Berent [C# MVP]" wrote:

> I simply added a new Row to my DataTable after clearing it. Since you're
> attempting to use the .Merge() method, could you tell me what your
> wsCommon.GetSpecificPerson(cmbSubject.Value) returns? Rows? DataSet?
> DataTable? I suspect the problem probably lies here somewhere.
>
> ~~Bonnie
>
>
>
> "WhiskyRomeo" wrote:
>
> > I simply clear the dataset and refill it. Here is the code that does that.
> > The only change that makes this work is the clear and adding of binding
> > before and after the merge.
> >
> > Sub FillEventPerson()
> >
> > DsEventPerson1.Clear()
> > With Me
> > .tbFName.DataBindings.Clear()
> > .tbLName.DataBindings.Clear()
> > .tbEmail.DataBindings.Clear()
> > .tbNotes.DataBindings.Clear()
> > End With
> >
> > DsEventPerson1.Merge(wsCommon.GetSpecificPerson(cmbSubject.Value))
> >
> > With Me
> > .tbFName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "FirstName")
> > .tbLName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "LastName")
> > .tbEmail.DataBindings.Add("Text", DsEventPerson1.tblSubject, "Email")
> > .tbNotes.DataBindings.Add("Text", DsEventPerson1.tblSubject, "Notes")
> > End With
> > 'rest of this code does not apply to this problem
> > RowCountB = 0
> > CurrentRowB = 0
> > Dim ds As New wsOrgEvent.dsSubjectFoto
> > ds.Merge(wsCommon.GetSpecificFotos(cmbSubject.Value))
> > dtFotosB = ds.tblSubjectFoto
> > RowCountB = dtFotosB.Rows.Count
> > Call InitializeDisplay()
> > ds = Nothing
> > End Sub
> >
> >
> >
> > "Bonnie Berent [C# MVP]" wrote:
> >
> > > Actually, though, I just had another thought. If you're simply clearing the
> > > DataSet, that shouldn't mess up your binding (although I haven't messed with
> > > it) ... how are you adding the new row back in?
> > >
> > > ~~Bonnie
> > >
> > >
> > > "WhiskyRomeo" wrote:
> > >
> > > > Since each event can have anywhere from 30 to 800 grads in them and since the
> > > > user is only interested in one or two grads when they use this form, each
> > > > selection in the combo box clears the dataset the textboxes are bound to and
> > > > retrieves exactly one record from the database.
> > > >
> > > > If, instead, I retrieved the entire event I would have worked with the
> > > > BindingContext Position. However, that isn't applicable in this case, since
> > > > there is only one record.
> > > >
> > > > wr
> > > >
> > > >
> > > > "Bonnie Berent [C# MVP]" wrote:
> > > >
> > > > > What code do you have in your ComboBox's .SelectedIndexChanged Event Handler?
> > > > > You need to move the BindingContext Position in order for the correct row to
> > > > > show up in the bound TextBoxes.
> > > > >
> > > > > ~~Bonnie
> > > > >
> > > > > "WhiskyRomeo" wrote:
> > > > >
> > > > > > I have a windows forms that shows only one record at a time.
> > > > > >
> > > > > > The user selects the record he want via a combo box. Everything works fine
> > > > > > for the first selection, however the textboxes do not automatically update
> > > > > > their values when the combo box changes values.
> > > > > >
> > > > > > The textboxes are bound to a dataset. Here is and an example of what the
> > > > > > databinding lookes like in designer:
> > > > > >
> > > > > > Text: DsEventPerson1 - tblSubject.FirstName
> > > > > >
> > > > > > When the user selects a new row in the combo box, the DsEventPerson1 is
> > > > > > cleared and refilled. What must I do to get the textboxes to show the
> > > > > > correct values for each record selected?
> > > > > >
> > > > > > --
> > > > > > wr

RE: Databinding to Textboxes by BonnieBerentCMVP

BonnieBerentCMVP
Sun Feb 20 12:35:03 CST 2005

Hmmm ... still should work. At least it does when I try it.

I poked around some more, on a hunch about the two different ways to add a
DataBinding, and I hit pay dirt. Here's what's going on ... you mentioned
something in an earlier post about how the DataBinding looked in the IDE
(PropertySheet, I assume), but didn't actually post what that looked like. I
think, maybe, that when the form initially Loads, that your DataBinding to
your TextBoxes, is of this format:

Me.tbFName.DataBindings.Add("Text", DsEventPerson1, "tblSubject.FirstName")

instead of this format:

Me.tbFName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "FirstName")

Note that this is actually two different DataBindings. I always use the
second version of it (as you have when you re-bind), because of problems I've
run into in the past with the first version. I think the first version of it
doesn't work correctly when Merging DataSets. I just tried it that way and
sure enough, it didn't show up correctly in the bound TextBox.

So, bottom line ... don't do the DataBinding in the PropertySheet, code it
by hand (using the second version) and everything should be fine. You should
then not have to unbind and rebind each time.

~~Bonnie




"WhiskyRomeo" wrote:

> it returns a dataset. Here is the code for that:
>
> <WebMethod()> Public Function GetSpecificPerson(ByVal intPerson_ID As Int32)
> As dsEventPerson
> Dim ds As New dsEventPerson
> 'Get Subjects
> daSpecificPerson.SelectCommand.Parameters("@Person_ID").Value = intPerson_ID
> daSpecificPerson.Fill(ds, "tblSubject")
>
> 'Get Subject Addresses
> daSpecificAddress.SelectCommand.Parameters("@Person_ID").Value = intPerson_ID
> daSpecificAddress.Fill(ds, "tblSubjectAddress")
>
> 'Get Associates
> daSpecificAssociate.SelectCommand.Parameters("@AssociatedSubject_ID").Value
> = intPerson_ID
> daSpecificAssociate.Fill(ds, "tblAssociate")
>
> 'Get Associate Addresses
> daSpecificAssociateAddress.SelectCommand.Parameters("@AssociatedSubject_ID").Value = intPerson_ID
> daSpecificAssociateAddress.Fill(ds, "tblAssociateAddress")
> Return ds
> End Function
>
> wr
>
> "Bonnie Berent [C# MVP]" wrote:
>
> > I simply added a new Row to my DataTable after clearing it. Since you're
> > attempting to use the .Merge() method, could you tell me what your
> > wsCommon.GetSpecificPerson(cmbSubject.Value) returns? Rows? DataSet?
> > DataTable? I suspect the problem probably lies here somewhere.
> >
> > ~~Bonnie
> >
> >
> >
> > "WhiskyRomeo" wrote:
> >
> > > I simply clear the dataset and refill it. Here is the code that does that.
> > > The only change that makes this work is the clear and adding of binding
> > > before and after the merge.
> > >
> > > Sub FillEventPerson()
> > >
> > > DsEventPerson1.Clear()
> > > With Me
> > > .tbFName.DataBindings.Clear()
> > > .tbLName.DataBindings.Clear()
> > > .tbEmail.DataBindings.Clear()
> > > .tbNotes.DataBindings.Clear()
> > > End With
> > >
> > > DsEventPerson1.Merge(wsCommon.GetSpecificPerson(cmbSubject.Value))
> > >
> > > With Me
> > > .tbFName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "FirstName")
> > > .tbLName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "LastName")
> > > .tbEmail.DataBindings.Add("Text", DsEventPerson1.tblSubject, "Email")
> > > .tbNotes.DataBindings.Add("Text", DsEventPerson1.tblSubject, "Notes")
> > > End With
> > > 'rest of this code does not apply to this problem
> > > RowCountB = 0
> > > CurrentRowB = 0
> > > Dim ds As New wsOrgEvent.dsSubjectFoto
> > > ds.Merge(wsCommon.GetSpecificFotos(cmbSubject.Value))
> > > dtFotosB = ds.tblSubjectFoto
> > > RowCountB = dtFotosB.Rows.Count
> > > Call InitializeDisplay()
> > > ds = Nothing
> > > End Sub
> > >
> > >
> > >
> > > "Bonnie Berent [C# MVP]" wrote:
> > >
> > > > Actually, though, I just had another thought. If you're simply clearing the
> > > > DataSet, that shouldn't mess up your binding (although I haven't messed with
> > > > it) ... how are you adding the new row back in?
> > > >
> > > > ~~Bonnie
> > > >
> > > >
> > > > "WhiskyRomeo" wrote:
> > > >
> > > > > Since each event can have anywhere from 30 to 800 grads in them and since the
> > > > > user is only interested in one or two grads when they use this form, each
> > > > > selection in the combo box clears the dataset the textboxes are bound to and
> > > > > retrieves exactly one record from the database.
> > > > >
> > > > > If, instead, I retrieved the entire event I would have worked with the
> > > > > BindingContext Position. However, that isn't applicable in this case, since
> > > > > there is only one record.
> > > > >
> > > > > wr
> > > > >
> > > > >
> > > > > "Bonnie Berent [C# MVP]" wrote:
> > > > >
> > > > > > What code do you have in your ComboBox's .SelectedIndexChanged Event Handler?
> > > > > > You need to move the BindingContext Position in order for the correct row to
> > > > > > show up in the bound TextBoxes.
> > > > > >
> > > > > > ~~Bonnie
> > > > > >
> > > > > > "WhiskyRomeo" wrote:
> > > > > >
> > > > > > > I have a windows forms that shows only one record at a time.
> > > > > > >
> > > > > > > The user selects the record he want via a combo box. Everything works fine
> > > > > > > for the first selection, however the textboxes do not automatically update
> > > > > > > their values when the combo box changes values.
> > > > > > >
> > > > > > > The textboxes are bound to a dataset. Here is and an example of what the
> > > > > > > databinding lookes like in designer:
> > > > > > >
> > > > > > > Text: DsEventPerson1 - tblSubject.FirstName
> > > > > > >
> > > > > > > When the user selects a new row in the combo box, the DsEventPerson1 is
> > > > > > > cleared and refilled. What must I do to get the textboxes to show the
> > > > > > > correct values for each record selected?
> > > > > > >
> > > > > > > --
> > > > > > > wr

RE: Databinding to Textboxes by WhiskyRomeo

WhiskyRomeo
Sun Feb 20 12:43:04 CST 2005

Wow! I appreciate your time on this.

I will try it as you say.

WhiskyRomeo

"Bonnie Berent [C# MVP]" wrote:

> Hmmm ... still should work. At least it does when I try it.
>
> I poked around some more, on a hunch about the two different ways to add a
> DataBinding, and I hit pay dirt. Here's what's going on ... you mentioned
> something in an earlier post about how the DataBinding looked in the IDE
> (PropertySheet, I assume), but didn't actually post what that looked like. I
> think, maybe, that when the form initially Loads, that your DataBinding to
> your TextBoxes, is of this format:
>
> Me.tbFName.DataBindings.Add("Text", DsEventPerson1, "tblSubject.FirstName")
>
> instead of this format:
>
> Me.tbFName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "FirstName")
>
> Note that this is actually two different DataBindings. I always use the
> second version of it (as you have when you re-bind), because of problems I've
> run into in the past with the first version. I think the first version of it
> doesn't work correctly when Merging DataSets. I just tried it that way and
> sure enough, it didn't show up correctly in the bound TextBox.
>
> So, bottom line ... don't do the DataBinding in the PropertySheet, code it
> by hand (using the second version) and everything should be fine. You should
> then not have to unbind and rebind each time.
>
> ~~Bonnie
>
>
>
>
> "WhiskyRomeo" wrote:
>
> > it returns a dataset. Here is the code for that:
> >
> > <WebMethod()> Public Function GetSpecificPerson(ByVal intPerson_ID As Int32)
> > As dsEventPerson
> > Dim ds As New dsEventPerson
> > 'Get Subjects
> > daSpecificPerson.SelectCommand.Parameters("@Person_ID").Value = intPerson_ID
> > daSpecificPerson.Fill(ds, "tblSubject")
> >
> > 'Get Subject Addresses
> > daSpecificAddress.SelectCommand.Parameters("@Person_ID").Value = intPerson_ID
> > daSpecificAddress.Fill(ds, "tblSubjectAddress")
> >
> > 'Get Associates
> > daSpecificAssociate.SelectCommand.Parameters("@AssociatedSubject_ID").Value
> > = intPerson_ID
> > daSpecificAssociate.Fill(ds, "tblAssociate")
> >
> > 'Get Associate Addresses
> > daSpecificAssociateAddress.SelectCommand.Parameters("@AssociatedSubject_ID").Value = intPerson_ID
> > daSpecificAssociateAddress.Fill(ds, "tblAssociateAddress")
> > Return ds
> > End Function
> >
> > wr
> >
> > "Bonnie Berent [C# MVP]" wrote:
> >
> > > I simply added a new Row to my DataTable after clearing it. Since you're
> > > attempting to use the .Merge() method, could you tell me what your
> > > wsCommon.GetSpecificPerson(cmbSubject.Value) returns? Rows? DataSet?
> > > DataTable? I suspect the problem probably lies here somewhere.
> > >
> > > ~~Bonnie
> > >
> > >
> > >
> > > "WhiskyRomeo" wrote:
> > >
> > > > I simply clear the dataset and refill it. Here is the code that does that.
> > > > The only change that makes this work is the clear and adding of binding
> > > > before and after the merge.
> > > >
> > > > Sub FillEventPerson()
> > > >
> > > > DsEventPerson1.Clear()
> > > > With Me
> > > > .tbFName.DataBindings.Clear()
> > > > .tbLName.DataBindings.Clear()
> > > > .tbEmail.DataBindings.Clear()
> > > > .tbNotes.DataBindings.Clear()
> > > > End With
> > > >
> > > > DsEventPerson1.Merge(wsCommon.GetSpecificPerson(cmbSubject.Value))
> > > >
> > > > With Me
> > > > .tbFName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "FirstName")
> > > > .tbLName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "LastName")
> > > > .tbEmail.DataBindings.Add("Text", DsEventPerson1.tblSubject, "Email")
> > > > .tbNotes.DataBindings.Add("Text", DsEventPerson1.tblSubject, "Notes")
> > > > End With
> > > > 'rest of this code does not apply to this problem
> > > > RowCountB = 0
> > > > CurrentRowB = 0
> > > > Dim ds As New wsOrgEvent.dsSubjectFoto
> > > > ds.Merge(wsCommon.GetSpecificFotos(cmbSubject.Value))
> > > > dtFotosB = ds.tblSubjectFoto
> > > > RowCountB = dtFotosB.Rows.Count
> > > > Call InitializeDisplay()
> > > > ds = Nothing
> > > > End Sub
> > > >
> > > >
> > > >
> > > > "Bonnie Berent [C# MVP]" wrote:
> > > >
> > > > > Actually, though, I just had another thought. If you're simply clearing the
> > > > > DataSet, that shouldn't mess up your binding (although I haven't messed with
> > > > > it) ... how are you adding the new row back in?
> > > > >
> > > > > ~~Bonnie
> > > > >
> > > > >
> > > > > "WhiskyRomeo" wrote:
> > > > >
> > > > > > Since each event can have anywhere from 30 to 800 grads in them and since the
> > > > > > user is only interested in one or two grads when they use this form, each
> > > > > > selection in the combo box clears the dataset the textboxes are bound to and
> > > > > > retrieves exactly one record from the database.
> > > > > >
> > > > > > If, instead, I retrieved the entire event I would have worked with the
> > > > > > BindingContext Position. However, that isn't applicable in this case, since
> > > > > > there is only one record.
> > > > > >
> > > > > > wr
> > > > > >
> > > > > >
> > > > > > "Bonnie Berent [C# MVP]" wrote:
> > > > > >
> > > > > > > What code do you have in your ComboBox's .SelectedIndexChanged Event Handler?
> > > > > > > You need to move the BindingContext Position in order for the correct row to
> > > > > > > show up in the bound TextBoxes.
> > > > > > >
> > > > > > > ~~Bonnie
> > > > > > >
> > > > > > > "WhiskyRomeo" wrote:
> > > > > > >
> > > > > > > > I have a windows forms that shows only one record at a time.
> > > > > > > >
> > > > > > > > The user selects the record he want via a combo box. Everything works fine
> > > > > > > > for the first selection, however the textboxes do not automatically update
> > > > > > > > their values when the combo box changes values.
> > > > > > > >
> > > > > > > > The textboxes are bound to a dataset. Here is and an example of what the
> > > > > > > > databinding lookes like in designer:
> > > > > > > >
> > > > > > > > Text: DsEventPerson1 - tblSubject.FirstName
> > > > > > > >
> > > > > > > > When the user selects a new row in the combo box, the DsEventPerson1 is
> > > > > > > > cleared and refilled. What must I do to get the textboxes to show the
> > > > > > > > correct values for each record selected?
> > > > > > > >
> > > > > > > > --
> > > > > > > > wr

RE: Databinding to Textboxes by WhiskyRomeo

WhiskyRomeo
Sun Feb 20 14:35:02 CST 2005

Regarding:
You might want to consider adding Bind, UnBind and ReBind methods to your
> base classes (along with your own IBind interface).

I am just now venturing into full object-oriented programming, while I
understand your suggestion conceputally, I am a little ways off from being
able to implement this. Do you have existing code to illustrate this. I can
read C#.

Again, I appreciate your time on this.

WR

"Bonnie Berent [C# MVP]" wrote:

> Well, then, I guess the solution you already found is probably the best one
> to use (dropping the bindings and then adding them back).
>
> You might want to consider adding Bind, UnBind and ReBind methods to your
> base classes (along with your own IBind interface). This makes it much easier
> when you have a lot of controls on your form, because those methods, at a
> Form level would call the methods in it's Controls collection for those
> controls that implement the IBind interface. You wouldn't have to do it for
> each TextBox (or whatever) yourself, you'd simply issue the Form UnBind and
> ReBind, and it would handle it all for you.
>
> ~~Bonnie
>
> "WhiskyRomeo" wrote:
>
> > Since each event can have anywhere from 30 to 800 grads in them and since the
> > user is only interested in one or two grads when they use this form, each
> > selection in the combo box clears the dataset the textboxes are bound to and
> > retrieves exactly one record from the database.
> >
> > If, instead, I retrieved the entire event I would have worked with the
> > BindingContext Position. However, that isn't applicable in this case, since
> > there is only one record.
> >
> > wr
> >
> >
> > "Bonnie Berent [C# MVP]" wrote:
> >
> > > What code do you have in your ComboBox's .SelectedIndexChanged Event Handler?
> > > You need to move the BindingContext Position in order for the correct row to
> > > show up in the bound TextBoxes.
> > >
> > > ~~Bonnie
> > >
> > > "WhiskyRomeo" wrote:
> > >
> > > > I have a windows forms that shows only one record at a time.
> > > >
> > > > The user selects the record he want via a combo box. Everything works fine
> > > > for the first selection, however the textboxes do not automatically update
> > > > their values when the combo box changes values.
> > > >
> > > > The textboxes are bound to a dataset. Here is and an example of what the
> > > > databinding lookes like in designer:
> > > >
> > > > Text: DsEventPerson1 - tblSubject.FirstName
> > > >
> > > > When the user selects a new row in the combo box, the DsEventPerson1 is
> > > > cleared and refilled. What must I do to get the textboxes to show the
> > > > correct values for each record selected?
> > > >
> > > > --
> > > > wr

RE: Databinding to Textboxes by BonnieBerentCMVP

BonnieBerentCMVP
Sun Feb 20 14:53:04 CST 2005

Hey, no problem! Lemme know if it works ....

~~Bonnie


"WhiskyRomeo" wrote:

> Wow! I appreciate your time on this.
>
> I will try it as you say.
>
> WhiskyRomeo
>
> "Bonnie Berent [C# MVP]" wrote:
>
> > Hmmm ... still should work. At least it does when I try it.
> >
> > I poked around some more, on a hunch about the two different ways to add a
> > DataBinding, and I hit pay dirt. Here's what's going on ... you mentioned
> > something in an earlier post about how the DataBinding looked in the IDE
> > (PropertySheet, I assume), but didn't actually post what that looked like. I
> > think, maybe, that when the form initially Loads, that your DataBinding to
> > your TextBoxes, is of this format:
> >
> > Me.tbFName.DataBindings.Add("Text", DsEventPerson1, "tblSubject.FirstName")
> >
> > instead of this format:
> >
> > Me.tbFName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "FirstName")
> >
> > Note that this is actually two different DataBindings. I always use the
> > second version of it (as you have when you re-bind), because of problems I've
> > run into in the past with the first version. I think the first version of it
> > doesn't work correctly when Merging DataSets. I just tried it that way and
> > sure enough, it didn't show up correctly in the bound TextBox.
> >
> > So, bottom line ... don't do the DataBinding in the PropertySheet, code it
> > by hand (using the second version) and everything should be fine. You should
> > then not have to unbind and rebind each time.
> >
> > ~~Bonnie
> >
> >
> >
> >
> > "WhiskyRomeo" wrote:
> >
> > > it returns a dataset. Here is the code for that:
> > >
> > > <WebMethod()> Public Function GetSpecificPerson(ByVal intPerson_ID As Int32)
> > > As dsEventPerson
> > > Dim ds As New dsEventPerson
> > > 'Get Subjects
> > > daSpecificPerson.SelectCommand.Parameters("@Person_ID").Value = intPerson_ID
> > > daSpecificPerson.Fill(ds, "tblSubject")
> > >
> > > 'Get Subject Addresses
> > > daSpecificAddress.SelectCommand.Parameters("@Person_ID").Value = intPerson_ID
> > > daSpecificAddress.Fill(ds, "tblSubjectAddress")
> > >
> > > 'Get Associates
> > > daSpecificAssociate.SelectCommand.Parameters("@AssociatedSubject_ID").Value
> > > = intPerson_ID
> > > daSpecificAssociate.Fill(ds, "tblAssociate")
> > >
> > > 'Get Associate Addresses
> > > daSpecificAssociateAddress.SelectCommand.Parameters("@AssociatedSubject_ID").Value = intPerson_ID
> > > daSpecificAssociateAddress.Fill(ds, "tblAssociateAddress")
> > > Return ds
> > > End Function
> > >
> > > wr
> > >
> > > "Bonnie Berent [C# MVP]" wrote:
> > >
> > > > I simply added a new Row to my DataTable after clearing it. Since you're
> > > > attempting to use the .Merge() method, could you tell me what your
> > > > wsCommon.GetSpecificPerson(cmbSubject.Value) returns? Rows? DataSet?
> > > > DataTable? I suspect the problem probably lies here somewhere.
> > > >
> > > > ~~Bonnie
> > > >
> > > >
> > > >
> > > > "WhiskyRomeo" wrote:
> > > >
> > > > > I simply clear the dataset and refill it. Here is the code that does that.
> > > > > The only change that makes this work is the clear and adding of binding
> > > > > before and after the merge.
> > > > >
> > > > > Sub FillEventPerson()
> > > > >
> > > > > DsEventPerson1.Clear()
> > > > > With Me
> > > > > .tbFName.DataBindings.Clear()
> > > > > .tbLName.DataBindings.Clear()
> > > > > .tbEmail.DataBindings.Clear()
> > > > > .tbNotes.DataBindings.Clear()
> > > > > End With
> > > > >
> > > > > DsEventPerson1.Merge(wsCommon.GetSpecificPerson(cmbSubject.Value))
> > > > >
> > > > > With Me
> > > > > .tbFName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "FirstName")
> > > > > .tbLName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "LastName")
> > > > > .tbEmail.DataBindings.Add("Text", DsEventPerson1.tblSubject, "Email")
> > > > > .tbNotes.DataBindings.Add("Text", DsEventPerson1.tblSubject, "Notes")
> > > > > End With
> > > > > 'rest of this code does not apply to this problem
> > > > > RowCountB = 0
> > > > > CurrentRowB = 0
> > > > > Dim ds As New wsOrgEvent.dsSubjectFoto
> > > > > ds.Merge(wsCommon.GetSpecificFotos(cmbSubject.Value))
> > > > > dtFotosB = ds.tblSubjectFoto
> > > > > RowCountB = dtFotosB.Rows.Count
> > > > > Call InitializeDisplay()
> > > > > ds = Nothing
> > > > > End Sub
> > > > >
> > > > >
> > > > >
> > > > > "Bonnie Berent [C# MVP]" wrote:
> > > > >
> > > > > > Actually, though, I just had another thought. If you're simply clearing the
> > > > > > DataSet, that shouldn't mess up your binding (although I haven't messed with
> > > > > > it) ... how are you adding the new row back in?
> > > > > >
> > > > > > ~~Bonnie
> > > > > >
> > > > > >
> > > > > > "WhiskyRomeo" wrote:
> > > > > >
> > > > > > > Since each event can have anywhere from 30 to 800 grads in them and since the
> > > > > > > user is only interested in one or two grads when they use this form, each
> > > > > > > selection in the combo box clears the dataset the textboxes are bound to and
> > > > > > > retrieves exactly one record from the database.
> > > > > > >
> > > > > > > If, instead, I retrieved the entire event I would have worked with the
> > > > > > > BindingContext Position. However, that isn't applicable in this case, since
> > > > > > > there is only one record.
> > > > > > >
> > > > > > > wr
> > > > > > >
> > > > > > >
> > > > > > > "Bonnie Berent [C# MVP]" wrote:
> > > > > > >
> > > > > > > > What code do you have in your ComboBox's .SelectedIndexChanged Event Handler?
> > > > > > > > You need to move the BindingContext Position in order for the correct row to
> > > > > > > > show up in the bound TextBoxes.
> > > > > > > >
> > > > > > > > ~~Bonnie
> > > > > > > >
> > > > > > > > "WhiskyRomeo" wrote:
> > > > > > > >
> > > > > > > > > I have a windows forms that shows only one record at a time.
> > > > > > > > >
> > > > > > > > > The user selects the record he want via a combo box. Everything works fine
> > > > > > > > > for the first selection, however the textboxes do not automatically update
> > > > > > > > > their values when the combo box changes values.
> > > > > > > > >
> > > > > > > > > The textboxes are bound to a dataset. Here is and an example of what the
> > > > > > > > > databinding lookes like in designer:
> > > > > > > > >
> > > > > > > > > Text: DsEventPerson1 - tblSubject.FirstName
> > > > > > > > >
> > > > > > > > > When the user selects a new row in the combo box, the DsEventPerson1 is
> > > > > > > > > cleared and refilled. What must I do to get the textboxes to show the
> > > > > > > > > correct values for each record selected?
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > wr

RE: Databinding to Textboxes by WhiskyRomeo

WhiskyRomeo
Mon Feb 21 10:31:05 CST 2005

Worked like a champ.

did you see my earlier response?

Regarding:
You might want to consider adding Bind, UnBind and ReBind methods to your
> base classes (along with your own IBind interface).

I am just now venturing into full object-oriented programming, while I
understand your suggestion conceputally, I am a little ways off from being
able to implement this. Do you have existing code to illustrate this. I can
read C#.

You have spent too much time on this as is -- so only if you have something
already done.

WR
"Bonnie Berent [C# MVP]" wrote:

> Hey, no problem! Lemme know if it works ....
>
> ~~Bonnie
>
>
> "WhiskyRomeo" wrote:
>
> > Wow! I appreciate your time on this.
> >
> > I will try it as you say.
> >
> > WhiskyRomeo
> >
> > "Bonnie Berent [C# MVP]" wrote:
> >
> > > Hmmm ... still should work. At least it does when I try it.
> > >
> > > I poked around some more, on a hunch about the two different ways to add a
> > > DataBinding, and I hit pay dirt. Here's what's going on ... you mentioned
> > > something in an earlier post about how the DataBinding looked in the IDE
> > > (PropertySheet, I assume), but didn't actually post what that looked like. I
> > > think, maybe, that when the form initially Loads, that your DataBinding to
> > > your TextBoxes, is of this format:
> > >
> > > Me.tbFName.DataBindings.Add("Text", DsEventPerson1, "tblSubject.FirstName")
> > >
> > > instead of this format:
> > >
> > > Me.tbFName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "FirstName")
> > >
> > > Note that this is actually two different DataBindings. I always use the
> > > second version of it (as you have when you re-bind), because of problems I've
> > > run into in the past with the first version. I think the first version of it
> > > doesn't work correctly when Merging DataSets. I just tried it that way and
> > > sure enough, it didn't show up correctly in the bound TextBox.
> > >
> > > So, bottom line ... don't do the DataBinding in the PropertySheet, code it
> > > by hand (using the second version) and everything should be fine. You should
> > > then not have to unbind and rebind each time.
> > >
> > > ~~Bonnie
> > >
> > >
> > >
> > >
> > > "WhiskyRomeo" wrote:
> > >
> > > > it returns a dataset. Here is the code for that:
> > > >
> > > > <WebMethod()> Public Function GetSpecificPerson(ByVal intPerson_ID As Int32)
> > > > As dsEventPerson
> > > > Dim ds As New dsEventPerson
> > > > 'Get Subjects
> > > > daSpecificPerson.SelectCommand.Parameters("@Person_ID").Value = intPerson_ID
> > > > daSpecificPerson.Fill(ds, "tblSubject")
> > > >
> > > > 'Get Subject Addresses
> > > > daSpecificAddress.SelectCommand.Parameters("@Person_ID").Value = intPerson_ID
> > > > daSpecificAddress.Fill(ds, "tblSubjectAddress")
> > > >
> > > > 'Get Associates
> > > > daSpecificAssociate.SelectCommand.Parameters("@AssociatedSubject_ID").Value
> > > > = intPerson_ID
> > > > daSpecificAssociate.Fill(ds, "tblAssociate")
> > > >
> > > > 'Get Associate Addresses
> > > > daSpecificAssociateAddress.SelectCommand.Parameters("@AssociatedSubject_ID").Value = intPerson_ID
> > > > daSpecificAssociateAddress.Fill(ds, "tblAssociateAddress")
> > > > Return ds
> > > > End Function
> > > >
> > > > wr
> > > >
> > > > "Bonnie Berent [C# MVP]" wrote:
> > > >
> > > > > I simply added a new Row to my DataTable after clearing it. Since you're
> > > > > attempting to use the .Merge() method, could you tell me what your
> > > > > wsCommon.GetSpecificPerson(cmbSubject.Value) returns? Rows? DataSet?
> > > > > DataTable? I suspect the problem probably lies here somewhere.
> > > > >
> > > > > ~~Bonnie
> > > > >
> > > > >
> > > > >
> > > > > "WhiskyRomeo" wrote:
> > > > >
> > > > > > I simply clear the dataset and refill it. Here is the code that does that.
> > > > > > The only change that makes this work is the clear and adding of binding
> > > > > > before and after the merge.
> > > > > >
> > > > > > Sub FillEventPerson()
> > > > > >
> > > > > > DsEventPerson1.Clear()
> > > > > > With Me
> > > > > > .tbFName.DataBindings.Clear()
> > > > > > .tbLName.DataBindings.Clear()
> > > > > > .tbEmail.DataBindings.Clear()
> > > > > > .tbNotes.DataBindings.Clear()
> > > > > > End With
> > > > > >
> > > > > > DsEventPerson1.Merge(wsCommon.GetSpecificPerson(cmbSubject.Value))
> > > > > >
> > > > > > With Me
> > > > > > .tbFName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "FirstName")
> > > > > > .tbLName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "LastName")
> > > > > > .tbEmail.DataBindings.Add("Text", DsEventPerson1.tblSubject, "Email")
> > > > > > .tbNotes.DataBindings.Add("Text", DsEventPerson1.tblSubject, "Notes")
> > > > > > End With
> > > > > > 'rest of this code does not apply to this problem
> > > > > > RowCountB = 0
> > > > > > CurrentRowB = 0
> > > > > > Dim ds As New wsOrgEvent.dsSubjectFoto
> > > > > > ds.Merge(wsCommon.GetSpecificFotos(cmbSubject.Value))
> > > > > > dtFotosB = ds.tblSubjectFoto
> > > > > > RowCountB = dtFotosB.Rows.Count
> > > > > > Call InitializeDisplay()
> > > > > > ds = Nothing
> > > > > > End Sub
> > > > > >
> > > > > >
> > > > > >
> > > > > > "Bonnie Berent [C# MVP]" wrote:
> > > > > >
> > > > > > > Actually, though, I just had another thought. If you're simply clearing the
> > > > > > > DataSet, that shouldn't mess up your binding (although I haven't messed with
> > > > > > > it) ... how are you adding the new row back in?
> > > > > > >
> > > > > > > ~~Bonnie
> > > > > > >
> > > > > > >
> > > > > > > "WhiskyRomeo" wrote:
> > > > > > >
> > > > > > > > Since each event can have anywhere from 30 to 800 grads in them and since the
> > > > > > > > user is only interested in one or two grads when they use this form, each
> > > > > > > > selection in the combo box clears the dataset the textboxes are bound to and
> > > > > > > > retrieves exactly one record from the database.
> > > > > > > >
> > > > > > > > If, instead, I retrieved the entire event I would have worked with the
> > > > > > > > BindingContext Position. However, that isn't applicable in this case, since
> > > > > > > > there is only one record.
> > > > > > > >
> > > > > > > > wr
> > > > > > > >
> > > > > > > >
> > > > > > > > "Bonnie Berent [C# MVP]" wrote:
> > > > > > > >
> > > > > > > > > What code do you have in your ComboBox's .SelectedIndexChanged Event Handler?
> > > > > > > > > You need to move the BindingContext Position in order for the correct row to
> > > > > > > > > show up in the bound TextBoxes.
> > > > > > > > >
> > > > > > > > > ~~Bonnie
> > > > > > > > >
> > > > > > > > > "WhiskyRomeo" wrote:
> > > > > > > > >
> > > > > > > > > > I have a windows forms that shows only one record at a time.
> > > > > > > > > >
> > > > > > > > > > The user selects the record he want via a combo box. Everything works fine
> > > > > > > > > > for the first selection, however the textboxes do not automatically update
> > > > > > > > > > their values when the combo box changes values.
> > > > > > > > > >
> > > > > > > > > > The textboxes are bound to a dataset. Here is and an example of what the
> > > > > > > > > > databinding lookes like in designer:
> > > > > > > > > >
> > > > > > > > > > Text: DsEventPerson1 - tblSubject.FirstName
> > > > > > > > > >
> > > > > > > > > > When the user selects a new row in the combo box, the DsEventPerson1 is
> > > > > > > > > > cleared and refilled. What must I do to get the textboxes to show the
> > > > > > > > > > correct values for each record selected?
> > > > > > > > > >
> > > > > > > > > > --
> > > > > > > > > > wr

RE: Databinding to Textboxes by BonnieBerentCMVP

BonnieBerentCMVP
Mon Feb 21 15:05:03 CST 2005

I typically keep text files of answers I've posted for FAQs, and I have some
examples of DataBinding methods, but I've not included stuff with
Unbind/Rebind examples. However, it might be worthwhile to throw something
together for that. Gimme a few days to get back to you on this ... if it
seems like I've forgotten after a few days, feel free to remind me ... I just
gotta find some extra spare time to cobble something together.

~~Bonnie


"WhiskyRomeo" wrote:

> Worked like a champ.
>
> did you see my earlier response?
>
> Regarding:
> You might want to consider adding Bind, UnBind and ReBind methods to your
> > base classes (along with your own IBind interface).
>
> I am just now venturing into full object-oriented programming, while I
> understand your suggestion conceputally, I am a little ways off from being
> able to implement this. Do you have existing code to illustrate this. I can
> read C#.
>
> You have spent too much time on this as is -- so only if you have something
> already done.
>
> WR
> "Bonnie Berent [C# MVP]" wrote:
>
> > Hey, no problem! Lemme know if it works ....
> >
> > ~~Bonnie
> >
> >
> > "WhiskyRomeo" wrote:
> >
> > > Wow! I appreciate your time on this.
> > >
> > > I will try it as you say.
> > >
> > > WhiskyRomeo
> > >
> > > "Bonnie Berent [C# MVP]" wrote:
> > >
> > > > Hmmm ... still should work. At least it does when I try it.
> > > >
> > > > I poked around some more, on a hunch about the two different ways to add a
> > > > DataBinding, and I hit pay dirt. Here's what's going on ... you mentioned
> > > > something in an earlier post about how the DataBinding looked in the IDE
> > > > (PropertySheet, I assume), but didn't actually post what that looked like. I
> > > > think, maybe, that when the form initially Loads, that your DataBinding to
> > > > your TextBoxes, is of this format:
> > > >
> > > > Me.tbFName.DataBindings.Add("Text", DsEventPerson1, "tblSubject.FirstName")
> > > >
> > > > instead of this format:
> > > >
> > > > Me.tbFName.DataBindings.Add("Text", DsEventPerson1.tblSubject, "FirstName")
> > > >
> > > > Note that this is actually two different DataBindings. I always use the
> > > > second version of it (as you have when you re-bind), because of problems I've
> > > > run into in the past with the first version. I think the first version of it
> > > > doesn't work correctly when Merging DataSets. I just tried it that way and
> > > > sure enough, it didn't show up correctly in the bound TextBox.
> > > >
> > > > So, bottom line ... don't do the DataBinding in the PropertySheet, code it
> > > > by hand (using the second version) and everything should be fine. You should
> > > > then not have to unbind and rebind each time.
> > > >
> > > > ~~Bonnie
> > > >
> > > >
> > > >
> > > >
> > > > "WhiskyRomeo" wrote:
> > > >
> > > > > it returns a dataset. Here is the code for that:
> > > > >
> > > > > <WebMethod()> Public Function GetSpecificPerson(ByVal intPerson_ID As Int32)
> > > > > As dsEventPerson
> > > > > Dim ds As New dsEventPerson
> > > > > 'Get Subjects
> > &g