Accessing Fields within a Collection from UIModel

Is it possible to programmatically access fields within a collection from UIModel.


In this case, I have a list of members in a collection. This collection includes a Is Primary Member field. I'd like to treat this like a radio button, where only one row may be set to true at any given time. I thought about handling this in TSQL, but if someone has clicked three or four people as the primary member, it's a bit of a mess. It would be better to handle this in VB or C# as the value is set on one row, to unset it for all others.


I figured accessing a field within a collection would be the logical place to start, but I can not seem to get any traction on this.


Any suggestions?


Thanks in advance.


Ernie Noa

Comments

  • The best way I found is to use foreach loops. You can loop through the collection fields value property that contains objects representing the rows in the collection. For example, you could try something like below to access them. You can also tie into the on-changed event handler for the collection field and access the field the same way to handle the logic. Hope this helps some.


    foreach (var m in MEMBERS.Value)

    {

    m.ISPRIMARY.Value =

    }


  • Hey Nick,


    This is very helpful, I did not know how to access child members of a collection. This has moved me forward a great deal. I wish there was better documentation regarding the methods and properties exposed in VB and C# via the UIModel. Documentation on the XML specs is quite good, but I am left guessing and experimenting with the VB and C#.


    I just need to find the right event which fires when a specific record is updated within a collection and how to determine which record called that event. I can set EVERYTHING during various events, but need to hang on to the most recently updated record. I'm close. I bet if I poke around the discussion groups, or elsewhere I can find an example of this.


    Thanks for helping. This was terrific.


    Best regards,


    Ernie
  • I got this running the way I wanted, but I don't really like the nested loops in my code. There is probably a much better way to find out what row is calling this procedure in my collection, but I haven't found it yet. Thanks again for the help, it got me moving. I had no idea how to access fields in a collection without the assist.


    Private Sub BulkCommitteeGroupMemberEditDataFormUIModel_UIFieldChanged(sender As Object, e As UIFieldChangedEventArgs) Handles Me.UIFieldChanged

    For Each m In GROUPMEMBERS.Value

    If m.Selected = True And m.ISPRIMARY.Value = True Then

    m.ISPRIMARY.Value = True

    For Each m2 In GROUPMEMBERS.Value

    If m2.Selected = False Then

    m2.ISPRIMARY.Value = False

    End If

    Next

    End If

    Next

    End Sub

Categories