mano
mano

Reputation: 308

Loosing previous selected data after Filtering a dataset in CxGrid

I am loosing previously selected lookupdata after Filtering a dataset which bound with the column in CxGrid of the type DBlookupcombox. please find below the details.

We have a cxGrid with columns

ID | Name  | Place 
1  |  abc  | Place1
2  |  xyz  | Place5
3  |  lmn  |
4  |  opq  |
5  |  rst  |


and another table Client
ClientID | Name
1        | abc  
2        | xyz   
3        | lmn 
4        | opq  
5        | rst  

In database, there is a table PlaceMapping
PlaceMappingID|  ClientID | Place
    1         |  1        | Place1
    2         |  1        | Place2
    3         |  2        | Place1
    4         |  2        | Place5
    5         |  2        | Place6

Based on the ID we are fetching the "Place" from table PlaceMapping which is of type DBLookupComboBox(under properties of cxgrid we have this option).

We have added the filter on the event "GetPropertiesForEdit" of cxGrid column Place. The Place lookupcombobox gets the correct values to be displayed however after the user selects any item and changes focus from the selected item. It goes blank.

I had tried removing the filter for Place column which works fine but it gets all the values of places.

Example: For ID "1" we get lookupcombobox with values Place1 and Place2.

For ID "2" we get lookup with values Place1, Place5, Place6.

Any help really appreciated.

Upvotes: 0

Views: 1534

Answers (1)

mano
mano

Reputation: 308

Got two ways working for me:

Way 1: Create two lookup tables. The first table is bound to the column's editor. It must contain all rows to properly display lookup values in all View records. The second table should be assigned to the in-place editor, once it is opened. This table will be filtered to contain a limited recordset as appropriate for the current field/record.

Instead of a filtered table, you may use a query which contains the WHERE clause with appropriate parameters.

Way 2: Instead of creating extra datasets, you may filter directly the dropdown lookup Grid. This Grid contains its own Data Controller and you may use all its properties and method similar to what you do for a Grid View.

Common part: The Table View object has the OnInitEdit event, which allows you to set up the in-place editor before it is displayed. You should use this event to populate combo box items, filter lookup lists, and change other editor properties. Using the editor's OnPopup or OnInitPopup events instead is not appropriate in this situation for two reasons: a) the editor needs correct lookup data to display an edit box value; b) a user can change the edit value without opening the dropdown list, for example, by typing in a column cell.

Within the OnInitEdit event handler we: 1) check whether the column is the one whose editor we need to modify; 2) form a filter for the auxiliary lookup table using a value of the current View record; 3) Way 1: replace the editor's list source with the data source, which binds to the filtered (auxiliary) lookup table; Way 2: set the filter of the lookup Data Controller.

Upvotes: 1

Related Questions