Bill G
Bill G

Reputation: 161

BindingSource AddNew() and initializing values

i have a ComponentOne FlexGrid bound to a bindingsource and the bindingsource is bound to a bindinglist collection.

The user clicks an insert button. I call AddNew() on the BindingSource. in the AddingNew() event, i want to initialize the properties in the bindingsource. usually if i want to access the data underlying the grid row i do this

MemberSkill skill = (MemberSkill)MemberSkillBS.Current

skill.SocSecNo = currentMember.SocSecNo;

but when i do this in the AddingNew() event, Current is still pointing to the row with the focus on the grid. how can i access the new item i added to the binding source and initialize it?

Upvotes: 0

Views: 6561

Answers (1)

Jacob Seleznev
Jacob Seleznev

Reputation: 8141

The new item becomes the current item after the AddNew has been called.

In your Insert button handler you do:

    private void buttonInsert_Click(object sender, EventArgs e)
    {
        MemberSkill newItem = MemberSkillBS.AddNew() as MemberSkill;
        if (newItem != null)
        {
            MemberSkillBS.Add(newItem);
        }
        ...
    }

and in your AddingNew handler you do:

    private void MemberSkillBS_AddingNew(object sender, AddingNewEventArgs e)
    {
         MemberSkill skill = new MemberSkill
        {
           SocSecNo = MemberSkillBS.Current.SocSecNo
        };
        e.NewObject = skill;
    }

Upvotes: 2

Related Questions