How to identify selected rows

imurphyimurphy Member Posts: 308
edited 2008-07-23 in NAV Tips & Tricks
Is is possible to identify the currently selected rows in a grid on a form?

I want the user to select a few rows with shift.click and to then click on a button to perform an action on those rows.

I thought it might be the Markedonly function but it doesn't appear to do what I want.

Comments

  • DenSterDenSter Member Posts: 8,304
    SETSELECTIONFILTER, look it up in the C/SIDE reference guide (in the help menu) :mrgreen:
  • imurphyimurphy Member Posts: 308
    I'm sitting here with D.Studebakers book and couldn't find anything related to the subject. Searching for selection/select etc on mibuso didn't turn up anything either.

    Thanks, all I needed was a starting point.

    Ian
  • DaveTDaveT Member Posts: 1,039
    Hi Ian,

    Look at the GetSelectionFilter() function on the main list forms (item,customer,vendor) which uses CURRFORM.GETSELECTIONFILTER funchion and is very useful :wink:
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • imurphyimurphy Member Posts: 308
    GetSelectionFilter???? I can't find any references to it anywhere. Where did you find it.

    Ian
  • DaveTDaveT Member Posts: 1,039
    Hi Ian,

    Lokk in the master list forms e.g. form 31 Item list - this function is used from the Analysis By Dimension form 7158 in the onlookup trigger of the item filter and works like

    item selected 1000,1001,1002,7000
    returns string 1000..1002|7000 8)
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • imurphyimurphy Member Posts: 308
    I've set up a button which the user will click on after selecting the rows they want. I have copied a few lines from form 31 to test this out. The onpush event handler looks like this:
    CurrForm.SETSELECTIONFILTER(SelectedSalesLine);
    SelectedSalesLine.FIND('-');
    SalesLineCount := SelectedSalesLine.COUNT;
    

    but it fails on the first line with an error saying
    Copying all filters at once can only be done between records belonging to the same table.
    Table: Sales Line <-- Sales Header
    Copy the necessary filters one at a time.
    But I haven't asked it copy anything so what is it going on about?

    The only documentation consists of a single, not very helpful line.

    When I am in a Sales Order (form 42) do I need to use CurrForm to refer to the sales line or should I be somehow tracking down the subform object and using that?

    What does the SetSelectionFilter method actually do?

    I have to pass it a record - but it doesn't say *what* record - will this contain the resultset or is it the set of records in the form?

    Since it doesn't return a result, what does it do with this record?
  • DaveTDaveT Member Posts: 1,039
    Hi Ian,

    The SETSELECTIONFILTER command works on the source table on the calling form so if your case the command will return Sales Header record(s) and you are trying to assign this to a sales line. If you want to select the subform that you will need to use the SETSELECTIONFILTER is the sub-form and process from there. If you want to button on the main form then write a function in the sub-from and call this from the main form.

    Hope this helps.
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • imurphyimurphy Member Posts: 308
    Aha, hadn't thought about writing a method on the subform.

    I've been digging around for a way to find a reference to the subform table.

    Thanks
    Ian
  • DaveTDaveT Member Posts: 1,039
    Glad to help :mrgreen:
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • imurphyimurphy Member Posts: 308
    Just in case someone else is trying this out for the first time, this works for me ...

    Modify the subform showing the lines you want the user to multi-select. Add a button and attach something like the code below to the onpush. It makes a change to each selected line on a grid.
    CurrForm.SETSELECTIONFILTER(SelectedSalesLine);
    SelectedSalesLine.FINDFIRST;
    SalesLineCount := SelectedSalesLine.COUNT;
    
    IF   SelectedSalesLine.FINDFIRST THEN
      REPEAT
        SalesLineCount := SalesLineCount - 1;
    
        IF SelectedSalesLine.Quantity <>0 THEN 
        BEGIN
        
          SelectedSalesLine."Qty. to Invoice" :=
              SelectedSalesLine.Quantity * (PercentageToAssign/100);
          SelectedSalesLine.MODIFY;
    
        END;
        //MESSAGE (SelectedSalesLine.Description );
      UNTIL SelectedSalesLine.NEXT = 0;
    
Sign In or Register to comment.