Yeah, I understand. I was just trying to point out that what you are doing is kind of running against the grain of how the BD works. This may work great in your situation, but it wouldn't work well in many others. I know I'm constantly attempting to reduce the trips to the database, reduce the amount of data returned, increase the efficiency of the queries I run because these all slow down the app. Thus, I wouldn't want to requery the database to get data I already had, which is what you are doing (you have a BO that already contains all the records, then you use to BD to query the database and get some subset of those records again). However, it may work fine for you, which is great.
Also, I don't think your suggested code would work because you still need to set a BO to populate that isn't your primary BO (otherwise it will reload that BO and you'll loose all the records not found). You might try to just sub-class the browse dialog, adding the desired functionality. You might add a generic method to replace the
ShowDialog method that accepts the source BO and then does everything you need:
public class NavBrowseDialog : BrowseDialog
{
// Shows the browse dialog, populates a local BO (so the source BO
// remains unchanged) and then navigates the source BO to the
// selected record in the browse dialog.
// Params:
// boToNav:= source bo
public DialogResult ShowDialogAndNav<T>(BusinessLayer boToNav) where T: BusinessLayer, new()
{
T localBoToPopulate = new T;
this.BusinessObjectToPopulate = localBoToPopulate;
if (this.ShowDialog() == DialogResult.OK && localBoToPopulate.Count > 0)
{
boToNav.NavigateToPrimaryKey(localBoToPopulate.Items[localBoToPopulate.PrimaryKey]);
}
}
}
I'm not sure that the generic is strictly needed, but I think you do, so your local BO is of the correct type.
Now your code would be:
private void btnSearch_Click(object sender, EventArgs e)
{
KVbrowseDialog.MyShowDialog<Business_Objekte.Basis.KundenBO>();
}