StrataFrame Forum

When I copy my "Search" BO used in the BrowseDialog to my "Real" BO used on the form

http://forum.strataframe.net/Topic20379.aspx

By Marcia G Akins - 10/27/2008

This code doesn't work becasue boProspectSearch.client_pk contains the PK of the first record even though I selected the 5th record in the grid. I know I should be able to do this because when I don't copy the data from the "Search" BO the form populated correctly with the selected record. So what do I need to do here?

Thanks!

private void brwProspects_BrowseDialogClosed(MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialogClosedEventArgs e)

{

// Copy the data from the prospect search business object

// to the clients business object

string[] lcFieldList = new string[] { "client_pk", "type_fk", "tier_fk", "company_nme", "company_ein", "stradd_nme", "stradd_sfx", "city_nme", "state_nme", "pcode_nme", "active_flg", "sales_fk", "relat_fk", "admin_fk", "analy_fk", "file_dir", "csz_dsc", "lastmod_nme", "lastmod_dte" };

Int32 lnClient_pk;

if (!boProspectSearch.IsEmpty)

{

lnClient_pk = boProspectSearch.client_pk;

boClients.CopyDataFrom(boProspectSearch.CurrentDataTable.DefaultView.ToTable(true, lcFieldList), MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable);

boClients.NavigateToPrimaryKey(lnClient_pk);

}

}

By Ivan George Borges - 10/27/2008

Hi Marcia.

Could it be that the record was a duplicate and didn't get copied?

By Marcia G Akins - 10/28/2008

Ivan George Borges (10/28/2008)

Could it be that the record was a duplicate and didn't get copied?

That is irrelevant. The primary key on all the duplicated records would be the same Smile

By Trent L. Taylor - 10/28/2008

Well, I am a little confused here as to what you were expecting, but you are copying out of the CurrentDataTable after a search.  When you do this, the record pointer is irrelevant.  There is no record pointer in a data table, and when you call the CopyDatafrom method, the CurrentRowIndex is going to be reset.  So here are a couple of points:

  1. When you call a browse and it returns a record set, the CurrentRowIndex is "synced" up with the BusinessObjectToPopulate associated with the BrowseDialog (this is not part of the data table).
  2. When you call a CopyDataFrom, you will need to save off and or reposition the record pointer yourself as the CopyDataFrom will move the CurrentRowIndex when clearing and refilling. 
  3. In the BrowseDialogClosed event, the BusinessObjectToPopulate should already have the CurrentRowIndex set, so if you want to seek or reposition the BO after the copy, save off the selected PK and then scall a NavigateToPrimarykey or a SeekToPrimarykey after you call the CopyDataFrom.
By Marcia G Akins - 10/28/2008

Trent L. Taylor (10/28/2008)
Well, I am a little confused here as to what you were expecting, but you are copying out of the CurrentDataTable after a search.  When you do this, the record pointer is irrelevant.  There is no record pointer in a data table, and when you call the CopyDatafrom method, the CurrentRowIndex is going to be reset.  So here are a couple of points:
  1. When you call a browse and it returns a record set, the CurrentRowIndex is "synced" up with the BusinessObjectToPopulate associated with the BrowseDialog (this is not part of the data table).
  2. When you call a CopyDataFrom, you will need to save off and or reposition the record pointer yourself as the CopyDataFrom will move the CurrentRowIndex when clearing and refilling. 
  3. In the BrowseDialogClosed event, the BusinessObjectToPopulate should already have the CurrentRowIndex set, so if you want to seek or reposition the BO after the copy, save off the selected PK and then scall a NavigateToPrimarykey or a SeekToPrimarykey after you call the CopyDataFrom.

The problem is that when the BrowseDialog is closed, boProspectSearch.CurrentRowIndex = 0 no matter which row in the search results grid I have clicked on and boProspectSearch.client_pk is always the client_pk from the first record in the search results grid Angry

By Trent L. Taylor - 10/28/2008

You are welcome to produce a sample the replicates your behavior and post it here, but if you look at the ShowDialog method in the SF source code in the BrowseDialog class, you will see that the BrowseDialogClosed event isn't called until the index has been set, so there may be another factor here in your code.  Also, we use a technique similar to this (for other purposes) in our medical software, so I am confident that it will work, but there just may be something else in the mix here.  Here is the code that I an referring to:

(I have also attacherd this image so you don't have to squint BigGrin)

  1. The dialog is shown and the results captured
  2. The CurrentRowIndex is set within the BusinessObjectToPopulate (_BusinessObject)
  3. The BrowseDialogClosed event is raised

So you can see that the CurrentRowIndex should be set at this point, so as I mentioned, there could be something else going on here that I cannot see in your snippet.  A code sample always helps when trying to work through problems like this.  Let me know if this doesn't get you going in the right direction.

By Marcia G Akins - 10/28/2008

Trent L. Taylor (10/28/2008)
  1. The dialog is shown and the results captured
  2. The CurrentRowIndex is set within the BusinessObjectToPopulate (_BusinessObject)
  3. The BrowseDialogClosed event is raised

So you can see that the CurrentRowIndex should be set at this point, so as I mentioned, there could be something else going on here that I cannot see in your snippet.  A code sample always helps when trying to work through problems like this.  Let me know if this doesn't get you going in the right direction.

 

OK - I think I know what is happening here. boProspectSearch is based on a ciew so no primary key is specified in the BP mapper. Therefore, loForm.SelectedPrimary key is Nothing Tongue.

Is there a way to tell the BO mapper that a field in the view is a primary key?

By Trent L. Taylor - 10/28/2008

Yup, go into the BO Mapper, right-click the BO in question, the open the Advanced Options.  You can override the Primary Key.  This was actually implemented for this very purpose (when mapping to views).  It has other uses as well, but this is what spawned this feature.

By Marcia G Akins - 10/28/2008

Trent L. Taylor (10/28/2008)
Yup, go into the BO Mapper, right-click the BO in question, the open the Advanced Options.  You can override the Primary Key.  This was actually implemented for this very purpose (when mapping to views).  It has other uses as well, but this is what spawned this feature.

Thanks a million, Trent! You are my hero!

By Trent L. Taylor - 10/28/2008

LOL...glad you found what you needed Smile