Udostępnij za pośrednictwem


Lookup example

The following example shows how to use the Customers and Prospects lookup form in Microsoft Dynamics GP to retrieve customer numbers for a Visual Studio Tools integration.

  1. Add a reference to the SmartList application assembly.

    The Customers and Prospects lookup is one of the enhanced lookups for Microsoft Dynamics GP that are contained in the SmartList dictionary.

  2. Add a Lookup button to the Visual Studio Tools form.

    Refer to Adding controls for details about how to add a control to a Visual Studio Tools form.

  3. Add the flag to track that a lookup was opened.

    In the GPAddIn class, add a static variable to track that a lookup was opened. The following C# example shows code that does this.

    // Flag to track that a lookup was opened
    

public static Boolean ReturnToLookup = false;

  1. Add code to open the lookup form.

    In the Click event for the Lookup button, add code that opens the lookup. The actions that this code must perform will depend on the lookup that you are using. Refer to the document "Calling Lookup Forms from Dexterity" in the Microsoft Dynamics GP SDK for information about the available lookups. For the Customers and Prospects lookup, the following actions must be performed:

    • The flag is set that indicates the lookup was opened by the Visual Studio Tools integration.

    • The CustomerLookup form must be opened.

    • The Initialize procedure on the CustomerLookup form must be called. This configures how data is displayed in the lookup.

    The following C# example shows how the Customers lookup is opened.

    private void CustomerLookup_Click(object sender, EventArgs e)
    

{ // Create a reference to the CustomerLookup form Microsoft.Dexterity.Applications.SmartListDictionary. CustomerLookupForm customerLookup = SmartList.Forms.CustomerLookup;

// Set the flag indicating that we opened the lookup
GPAddIn.ReturnToLookup = true;

// Open the CustomerLookup form
customerLookup.Open();

// Call the Initialize procedure to configure the Customer Lookup
customerLookup.Procedures.Initialize.Invoke(1, 0,CustomerNumber.Text, "", "", "", "", "");

}

  1. Register the ClickBeforeOriginal event for the Select button.

    In the Initialize method of the GPAddIn class, register the ClickBeforeOriginal event of the Select button on the CustomerLookup window. The following C# example shows this registration.

    // Select button on the Customers lookup window
    

Microsoft.Dexterity.Applications.SmartListDictionary.CustomerLookupForm customerLookupForm = SmartList.Forms.CustomerLookup; customerLookupForm.CustomerLookup.SelectButton.ClickBeforeOriginal += new System.ComponentModel.CancelEventHandler(SelectButton_ClickBeforeOriginal);

  1. Return the ID of the selected item.

    In the event handler for the ClickBeforeOriginal event of the Select button, check the flag that indicates whether the Visual Studio Tools add-in opened the lookup. If it did, then return the customer number for the customer selected in the scrolling window of the Customers and Prospects lookup. The following C# example shows the event handler that performs these actions.

    void SelectButton_ClickBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e)
    

{ // Run this code only if the add-in opened the lookup. if (GPAddIn.ReturnToLookup == true) { // Retrieve the customer number of the row selected in the // scrolling window of the Customers lookup. Microsoft.Dexterity.Applications.SmartListDictionary. CustomerLookupForm customerLookupForm = SmartList.Forms.CustomerLookup; string customerNumber = customerLookupForm.CustomerLookup.CustomerLookupScroll.CustomerNumber.Value;

    // Display the value retrieved
    LookupsWindow.CustomerNumber.Text = customerNumber;

    // Clear the flag that indicates a value is to be retrieved from
    // the lookup.
    GPAddIn.ReturnToLookup = false;
}

}