Results 1 to 3 of 3

Thread: WinForms Binding to sub property and binding sub controls in a data repeater?

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    WinForms Binding to sub property and binding sub controls in a data repeater?

    This is WinForms BTW:

    ... just say I have an object that is like this:

    vb Code:
    1. Public class Address
    2.     Public Property UnitNo as integer
    3.     Public Property HouseNo as integer
    4.     Public Property Street as string
    5.     '....
    6. end class
    7. Public class Person
    8.     Public Property FirstName as string
    9.     Public Property Address as new Address
    10. End Class

    Just wondering if it's possible to bind to the Persons.street in a data repeater??

    The following works fine ... until it's in a data repeater and then it doesn't work:
    vb Code:
    1. TextBox1.DataBindings.Add(New Binding("Text", bs, "Address.Street", False, DataSourceUpdateMode.OnPropertyChanged))

    ...Also the same also seems to apply for sub controls in a data repeater... (in the case below MyTestControl is a control on the data repeater that exposes TextBox1 that is on it this applies when you don't try to bind to a sub property on the bs):
    vb Code:
    1. MyTestControl.TextBox1.DataBindings.Add(New Binding("Text", bs, "FirstName", False, DataSourceUpdateMode.OnPropertyChanged))

    Any ideas? ... This is really frustrating@!
    Thanks,
    Regards,
    Kris

  2. #2

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Re: WinForms Binding to sub property and binding sub controls in a data repeater?

    I have attached a test case project here so that you can see what I mean:

    DataRepeaterIssues.zip

    Thanks,
    Kris

  3. #3

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Re: WinForms Binding to sub property and binding sub controls in a data repeater?

    The only way I can work out of doing it is manually binding on the DrawItem event ... would be nice to do it on the ItemCloned event ... but the e.DataRepeaterItem.ItemIndex is always 0 when that happens

    Would be nice if they had an ItemDataSet event or something so I could do it there.

    vb Code:
    1. Private Sub DataRepeater1_DrawItem(sender As Object, e As PowerPacks.DataRepeaterItemEventArgs) Handles DataRepeater1.DrawItem
    2.         Dim ctl = e.DataRepeaterItem.Controls.OfType(Of UserControl1)().FirstOrDefault()
    3.         If ctl IsNot Nothing Then
    4.             Dim theObject = bs(e.DataRepeaterItem.ItemIndex)
    5.             If ctl.TextBox1.DataBindings.Count = 0 Then
    6.                 ctl.TextBox1.DataBindings.Add(New Binding("Text", theObject, "Name", False, DataSourceUpdateMode.OnPropertyChanged))
    7.             End If
    8.         End If
    9.  
    10.     End Sub

    Any better ideas?
    Thanks,
    Kris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width