How to get the number of the selected records in a grid

maria_iva81maria_iva81 Member Posts: 39
edited 2006-02-20 in Dynamics AX
Hi there does any body know how to get the number of selected records in a grid.
For example CustTransOpen_ds.mark() does not return it. Please help. I would like to check if the number is > 1 so that i can throw error

Comments

  • MugurMugur Member Posts: 93
    A solutions is this:

    int i;
    smmMailings smmMailings1;
    ;

    super();

    smmMAilings1 = smmMailings_ds.getFirst(true);
    while (smmMailings1)
    {
    i++;
    smmMailings1 = smmMailings_ds.getNext();
    }

    info(int2str(i));

    Best regards,
    Ciprian
    Kind regards,

    Ciprian Dudau
    Axapta Developer
  • maria_iva81maria_iva81 Member Posts: 39
    I have a checkbox infront of every line in the datagrid.I would like to get the number of the lines that have marked checkboxes..This is the code i use to see their number but i is always equal to 1,,,
    for (CustTransOpen = CustTransOpen_ds.getFirst(true) ? CustTransOpen_ds.getFirst(true) :
    CustTransOpen_ds.cursor(); CustTransOpen; CustTransOpen = CustTransOpen_ds.getnext())
    {
    i ++;
    }

    info(int2str(i));
    I have now idea how else to do it..Please help
  • MugurMugur Member Posts: 93
    Hi,

    The code is always returning 1 because it is looking only for selected records (meaning highlighted while holding Shift/Ctrl).

    For the selection you are trying to implement there is no Axapta trick... just try to see what the check box represents. Is it a field, a display method; does it belongs to the same datasource as the other fields or not etc.

    E.g.: If a field, perform a query against the datasource by maintaining the same filters as in the form and in addition use another filter (range) for the checkbox field with the value NoYes::Yes.

    Then you should count the number of recs in this query. Axapta provides a class method to ease this operation: SysQuery::countTotal(queryRun).

    Please let me know if you have still have problems, but be more specific with the problem details. A checkbox can mean many things.. :D
    Kind regards,

    Ciprian Dudau
    Axapta Developer
  • maria_iva81maria_iva81 Member Posts: 39
    Thanks for helping me again :)
    This checkbox represents a datamethod in the form CustOpenTrans called markTrans(this a method for the datasource CustTransOpen). I would like to write something like:
    select count(recid) from CustTransOpen where CustTransOpen.checkboxvalue == NoYes::Yes but i don't know how to get the value of the checkbox since it's not a field, but a method for the datasource.
  • MugurMugur Member Posts: 93
    Hi Maria,

    Should I understand that the code is for the Open transactions editing (CustTransOpen) form?

    ONLY if Yes, you can successfully use this code (otherwise please let me know what is the name of the form; however you can still use the code as reference):

    CustTransOpen testCustTransOpen;
    CustTrans testCustTrans;
    int i;
    ;

    while select testCustTransOpen
    WHERE testCustTransOpen.AccountNum==CustTransOpen.AccountNum
    JOIN testCustTrans
    WHERE testCustTransOpen.AccountNum==testCustTrans.AccountNum &&
    testCustTransOpen.RefRecId==testCustTrans.RecId
    {
    if (specOffsetVoucher.checkExist(testCustTransOpen.recID) &&
    !specOffsetVoucher.isMarkedElsewhere(testCustTransOpen.RecId, common.RecId))
    {
    i++;
    info (testCustTrans.Voucher);
    }
    }
    if (i>1)
    {
    throw error("There are more than one transactions marked!");
    }
    else
    {
    info("Transactions are marked correctly.");
    }
    Kind regards,

    Ciprian Dudau
    Axapta Developer
  • maria_iva81maria_iva81 Member Posts: 39
    Thanks a million this is what i needed it's just such a wierd way to get the count of the lines with the checked checkboxes...If you can give smo details about the purpose of this class and its methods , i mean specOffsetVoucher, cause i didn't find anything in the help system. Once again thanks for helping me :)
  • MugurMugur Member Posts: 93
    Glad to be of help. Regarding the class I really don't know much. I deducted the conditions from the code in MarkedTrans() method :) . It is obvious that it is responsible of handling the logic of marking customer open transactions. To find much see the methods in the class / use the Debugger while running the form. You can also use the Code explorer add-in tool to browse the code of an object.

    Regarding the code documenting, you probably noticed that very few classes/methods have documentation (mostly the system classes). That's why you have to learn directly from code... :roll:

    Best regards,
    Ciprian
    Kind regards,

    Ciprian Dudau
    Axapta Developer
  • maria_iva81maria_iva81 Member Posts: 39
    Hi there :) After limiting the number of checked lines to 1 the next step is to get this line and pass it to another form. I made a display menu item and in its click method i use args class to pass it. The problem is that i write : args.parm(CustTrans.Invoice); which is not correct :( (beacause it doesn't give the selected record)but i don't know what criteria to use to get this very invoice that has its checkbox checked....Please help
  • vulamvulam Member Posts: 24
    IF you only need to pass one record to other form then you can use the Args.record. not sure the corrected syntax but my guess is as follow
    Args.Record(CustTrans);

    Or you can store all the recid that you wanted in a container and pass it to other form
    Args.Parm(container); // please correct me if i'm wrong as i very very new to axapta.


    Or you can pass the current FormDataSource to other Form and from there you can use the sample codes giving to you by Mugur to retrieve those records that you wanted.

    hope my contribution can help or make sense. :roll:
Sign In or Register to comment.