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