StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
|
|
|
Alex M. Lana
|
|
Group: Forum Members
Posts: 20,
Visits: 264
|
Thanks for the example Ben, it was exactly that. Alex
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
Aha, you don't want to add a new NavigatedEventArgs to the handler, you want to add a new method delegate to the handler... like this: using MicroFour.StrataFrame.Business; namespace SomeNamespace { public class SomeClassHandlingTheNavigatedEvent { private void AddHandlerToBusinessObject(BusinessLayer bo) { bo.Navigated += new BusinessLayer.NavigatedEventHandler(this.MyNavigatedHandlingMethod); } private void MyNavigatedHandlingMethod(NavigatedEventArgs e) { //-- Do whatever you want with the e.[properties] // as they will contain the indexes and such } } }
The difference here is that you use the constructor of the event handler and pass the name of the method you want to execute. Then, when the business object wants to fire it's Navigated event, it will call your method. Also, if you've dropped a business object on a form, you can easily add a new event handler by going to the property sheet for the business object and clicking the events tab (the little lightning bolt at the top of the property sheet). Scroll down to the Navigated event and double-click it. The designer will add the handler and take you to the code file to the method that it created for you.
|
|
|
Alex M. Lana
|
|
Group: Forum Members
Posts: 20,
Visits: 264
|
Thanks Ben, exactly this I'm trying to acomplish, but it seems that SF C# classes miss some methods present in VB. I can't find anything to send as: MicroFour.StrataFrame.Business.BusinessNavigatedPosition NavigatedPositionArgand IsCurrentDataTableRefilledthis.sysProdutoBO1.Navigated += new MicroFour.StrataFrame.Business.NavigatedEventArgs(
??? this.SysProdutoBO1.NavigatedPositionArg ???,
this.sysProdutoBO1.CurrentRowIndex,
??? this.sysProdutoBO1.IsCurrentDataTableRefilled ???);
namespace MicroFour.StrataFrame.Business
{
public class NavigatedEventArgs : EventArgs
{
// Summary:
// Initializes a new instance of the NavigatedEventArgs class.
//
// Parameters:
// NavigatedPositionArg:
//
// CurrentRowIndexArg:
public NavigatedEventArgs(BusinessNavigatedPosition NavigatedPositionArg, int CurrentRowIndexArg, bool IsCurrentDataTableRefilled);
// Summary:
// Gets the absolute index of the newly selected record within the business
// object.
public int CurrentRowIndex { get; }
//
// Summary:
// Gets a value that indicates whether this navigation was the result of the
// CurrentDataTable being refilled.
public bool IsCurrentDataTableRefilled { get; }
//
// Summary:
// Gets a value that indicates where the newly selected record is in relation
// to the entire visible recordset.
public BusinessNavigatedPosition NavigatedPosition { get; }
}
}
Hope you can help me, I think it may be pretty simple. I only need a simple C# version of this VB code: Private Sub sysProdutoBO1_Navigated(ByVal e As MicroFour.StrataFrame.Business.NavigatedEventArgs) Handles sysProdutoBO1.Navigated
End Sub Thanks, Alex
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
Yep, that is the correct way to attach to an event in C#. The AddHandler and RemoveHandler keywords are not available in C#, so the overload of the +/- operators is used to add/remove method calls to delegate variables (events). So, to add the event: obj.EventName += new EventHandlerType(EventHandlerMethodName); and to remove the event handler, it's the - operator. I honestly can't remember whether you have to save off the created delegate in a variable to remove it or if you can just use the line above and swap the + for a -... not sure. Also note that C# does not have the Handles keyword or WithEvents keyword like VB does, so when you double-click a button in the designer and it creates the Click handler method for you, it is explicitly adding the line above for the event handler within the .designer.cs file for the form.
|
|
|
Alex M. Lana
|
|
Group: Forum Members
Posts: 20,
Visits: 264
|
Hi Greg, thanks for your reply. In the meantime I've already done the same, but my problem is to construct the navigated object in C#. I'm doing like this: // Fetch Child Data on Parent BO Navigation
private void sysProdutoBO1_Navigated(MicroFour.StrataFrame.Business.NavigatedEventArgs currNavig)
{
if (this.sysProdutoBO1.for_cod > 0)
{
this.sysFornecedorBO1.FillByPrimaryKey(this.sysProdutoBO1.for_cod);
}
} The question I have now is how to construct it at Designer.cs this.sysProdutoBO1.Navigated += new MicroFour.StrataFrame.Business.NavigatedEventArgs(this.sysProdutoBO1_Navigated); I don't know which parameters to send, and if is this the right way to grab the event in C#. Thanks everyone for the attention, regards, Alex
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
Peter Denton (10/31/2007) G'day
It may be that I'm not understanding what you are trying to do, but I was looking for answers to similar problems a few months ago until the lightbulb came on. When you define the parent-child relationship (as indicated by Ivan)you then fill both the parent and child BOs with all the recordsfrom the related table/view when the form loads and SF takes care of it from there, you don't have to refresh the child BO. If there is too much data then you will have to do as Greg suggested.
PeterYeah, the method I suggested is definitely directed toward reducing the data pulled across the network. Most of my users are remote
|
|
|
Ivan George Borges
|
|
Group: StrataFrame MVPs
Posts: 1.9K,
Visits: 21K
|
Hi Alex. Guess Greg has direct you already. But, still, give a good look at the SampleCRMApplication's CustomerMaintenance code. Maybe you have already and I am being redundant here... if so, sorry! In there, you will find many interesting guys: Customers_EditingStateChanged, Customers_Navigated, FillByParentPrimaryKey, SeekToPrimaryKey... Um ótimo dia!
|
|
|
Peter Denton
|
|
Group: Forum Members
Posts: 77,
Visits: 787
|
G'day It may be that I'm not understanding what you are trying to do, but I was looking for answers to similar problems a few months ago until the lightbulb came on. When you define the parent-child relationship (as indicated by Ivan) you then fill both the parent and child BOs with all the records from the related table/view when the form loads and SF takes care of it from there, you don't have to refresh the child BO. If there is too much data then you will have to do as Greg suggested. Peter
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
Alex, I think what you want is to handle the parent BO's navigated event. In that event, test if the FK is present and either load the child or clear it. E.g. If you have a ProductBO and an VendorBO, your Navigated event handler might look something like this: Private Sub ProductBO_Navigated(e As NavigatedEventArgs)
'-- Test if the product has a vendor, assuming that the VendorID has
' has been setup to be zero if it's null in the db...you could also use a
' nullable type and the appropriate test with that data type.
If Me.ProductBO.VendorID > 0 Then
'-- Load the vendor associated with this product
Me.VendorBO.FillByPrimaryKey(Me.ProductBO.VendorID)
Else
'-- No vendor, so clear vendor Bo
Me.VendorBO.Clear()
End If
End Sub Hope that helps!
|
|
|