Check - Uncheck all Checkboxes in Grid

Dears,

I have form with grid, the grid is filling from datasource, I have added a checkbox field into grid row. There is another checkbox in the form with label select all. I want if the select all checkbox is checked then all the checkboxes with grid rows must be checked, if select all is unchecked then all the grid associated checkboxes must be unchecked.

How should I do this?

Thanks.

What exactly “all” means? For example, if you display some records and a user adds some filters, should should it honor or ignore user-defined filters? Should it mark all records corresponding to the query or just those visible in the grid?

Dear Martin Dráb,

Thanks for your reply,

Firstly I want it as ignore the user filter.

If it checked according to user filtered records then it will be preferred.

hi khaksar

use this code in a button :


Table_Name a;

for (a = Table_ds.getFirst(true) ?

Table_ds.getFirst(true) :a; a; a = Table_ds.getNext())

{

a.check_box.checked=true;

}

write a method in Modified method

If(checkbox)

{

update_recordset table
setting field == NoYes::Yes
}
else
{

```
update_recordset table
setting field == NoYes::No
```

}
Datasource.refresh();

Dear Montazeri sb,

Thanks for your reply.

But I havn’t any checkbox at datasource level, it is a checkbox field in Form Grid which I added explicitly.

Dear all,

following is attached screen shot,

with select all checkbox all the appearing checkboxes in grid row (grid row checkbox is not from datasource table) will checked and also for unchecking.

Hope that my question is now clear to you.

0247.question.jpg

This concept achived by Map

the follwoing code to try your scenario

step 1: Form classDeclartion

Map SelectionMap;

step 2 : Add method

Map SelectedPost()

{

return SelectionMap;

}

step : 3 Add methods in Form datasource

edit NoYesId Selection(boolean _set,

datasourceName _datasourcename ,

NoYesId _value)

{

;

if(_set)

{

if(_value)

{

SelectionMap.insert(_datasourcename.RecId,_datasourcename);

}

else

{

SelectionMap.remove(_datasourcename.RecId);

}

}

return SelectionMap.exists(_datasourcename.RecId);

}

step 4 : add clikced method for (Select All Ctrl)

public void clicked()

{

super();

element.SelectAllNew();

}

step 5 : Code for electAllNew methods

vod SelectAllNew()

{

if(ChkSelectAll.value())

{

Datasourcename_ds.selection(true,Datasourcename,Noyes::Yes);

}

else

{

Datasourcename_ds.selection(true,Datasourcename,Noyes::No);

}

Datasourcename_ds.research(true);

}

Dear Sayed Abuthahir,

Thanks for your nice reply,

I have already did this thing, Just now I want to show to the user that all the rows are selected. I means just to mark the checkboxes in the grid by checking select all, and unmark the checkboxes in the grid by unchecking select all.

If you have a display method, you can simply return true or false depending on the value of the checkbox.

Sorry Martin,

Can you be more specific?

If you use a map, you can add / remove all records when the filter changes, but it may have negative impact on performance, if you have many records. One improvement may be using a TempDB table (AX 2012) instead of the collection in memory.

Or you can consider filtering for All and None as special cases:

edit NoYesId selection(
    boolean _set,
    Table1 _table1,
    NoYesId _value)
{
    if (_set)
    {
        ...
    }
    else
    {
        switch (filter.selection())
        {
            case MyFilterType::None:
                return false;
            case MyFilterType::All:
                return true;
        }
    }

    return selectionMap.exists(_table1.RecId);
}