In this particular instance I am using a listview control to display user names that can access my application. There are 2 custom fields whose content is fetched from another table. I have the listview bound to a business object which reads my usernamesBO. Each user has an entry in a userprofiles table which contains a boolean flag saying if they are logged into the application and the name of the computer they are using.
My listview displays the username, description, Computer Name, Logged In
There is a toolbar with Save Cancel Add Edit Delete
When the user click Add or Edit a child form is displayed allowing to make changes to the user profile. The BO is passed as an argument to the child form. If the user Add's a new profile, I execute a BO.NewRow() followed by assigning data to the fields. The ComputerName and LoggedIn are initialised to default values. The form is disposed an the user is returned to the parent form which excutes a listView.Requery(). Here, I am trying to display the new row.
The Requery causes the following event to be invoked:
// Populate computer name and logged-in status
private void listViewUserNames_RowPopulating(MicroFour.StrataFrame.UI.Windows.Forms.RowPopulatingEventArgs e)
{
HLSUserNamesBO loBO= (HLSUserNamesBO)e.BusinessObject;
if (this.hlsUserProfilesBO1.Seek("userId = " + loBO.userId.ToString()))
{
e.Values[2].DisplayValue = this.hlsUserProfilesBO1.computerName;
e.Values[3].DisplayValue = (Boolean)this.hlsUserProfilesBO1.loggedIn ? Global.RetrieveTextValue("Text_Yes") : Global.RetrieveTextValue("Text_No");
}
else
{
e.Values[2].DisplayValue = "";
e.Values[3].DisplayValue = Global.RetrieveTextValue("Text_No");
}
}
This code works fine when the form is initially loaded but when I return from the Add command, the section LoggedIn section causes the exception to be raised. On load the first Id =1 and this loads ok, the second record load ok. When I return from Add the first Id =1 and it fails.
I'm not sure why this is.
Can anyone priovide an explanation or solution?
Many thanks