Description:
I would like to have a column in my database-aware view for specific purposes, but I do not need to store the values of this column in the underlying table. Thus, I do not want to add an extra field to the database table's structure.
Answer:
If you wish to use this column for selection purposes, you can enable our web-style selection checkboxes.
If you need a generic checkbox column, you can create an empty column, use HitTests to respond to user actions, handle the OnGetDataText or OnCustomDrawCell event to display text, and store values in a separate structure (e.g., an array or a dictionary).
If you need to implement an unbound column with a textbox editor, follow these steps:
- Handle OnInitEditValue and OnEditValueChanged events to initialize and store a column value.
- Assign the column's DataBinding.ValueTypeClass.
Delphiuses
cxDataStorage;
...
aCol.DataBinding.ValueTypeClass := TcxStringValueType;
The attached project illustrates the general idea. You need to replace FValues and FStates arrays with your own structure (e.g., based on TDictionary
), and manually sort them and add or delete their values when the view's structure is changed. DataController.OnDataChanged may help you detect this change.
See also:
How to display an image from a data table in an Unbound View
How to show a row number value in an unbound Grid column
How to set an item's Properties at runtime
Hi,
Is this still working in VCL Version 12.2.5 ? I cannot achieve editing an unbound column.
Thanks in advance for your answer.
I mean, in a DBTable View
Hello Nico,
To process your inquiry more efficiently, I have created a separate ticket on your behalf: Q377298: How to set up an unbound item in a data-aware View.
What is the workaround for your disclaimer that SmartRefresh cannot be used in detail datasets? How do I store calculated values in cells of unbound detail tables?
Note: I could use an InternalCalc field to do this, however it only updates the data on post - I need the data update when a value is edited (at least at the point where a cell value is edited). Note: I was using OnGetDisplayText however I can't get a total from that.
InternalCalc field is the way to go, just set up corresponding checkbox editor to immediately post modified value into dataset as soon as it is (un-)checked
Vladimir is absolutely right. If you force your in-place editor to update data immediately, the InternalCalc field will be calculated right after you modify an editor value.
Hello, I'm trying to create the unbound checkbox at runtime after open the dataset. My problem is that I create the DataSet at runtime when the user open an Excel File, so the dataset is created with the Excel's columns structure. I followed all the steps in this ticket but it doesn't work, also I need the checkbox as the first column. Attached is the project, hope you can help me.
Thanks
Luis, i have tried your project.
I think it comes down to 2 issues, first of all make sure to set the keyfieldnames to the view.datacontroller and secondly the 'editing' flag in your view's OptionData properties is set to False.
You can not check the checkboxes because of setting the Editing option to false, so the solution is to enable editing in your view properties Optionsdata.
If you want the other columns to be readonly set them to readonly individually in runtime after you created the columns (before creating the checkbox column)
Hello,
Franky is absolutely right. I see that you set the grdTableView.DataController.KeyFieldNames property to 'aUniqueField' in your project. However, there is no such a field in your underlying DataSet. To make unbound columns work OK, you need to have a unique key field in your database. Otherwise, in SmartRefresh mode, there will be no way to identify a certain record.
As for your question about the checkbox column, you can use the Index property to change the column's position:
aCol.Index := 0;
Hi,
How can I then access which checkbox was changed/clicked and its value (true/false)?
Regards
Hello Klemen,
I've created a separate ticket on your behalf (T553081: How can I access which checkbox was changed/clicked in an unblund column and get its value (true/false)?). It has been placed in our processing queue and will be answered shortly.
Hi all!
I have add a checkbox to my Grid described in this article. The checkbos is visible when programm run - but i cannot klick to change the value. The checkbox in every row is "greyed". Perhaps the reason is, that i dont have a "TcxGridDBTbleView.Filer.KeyFieldName". In the Table the primrary key is over 2 Fields (Order-No. and Order-Position).
Is it possible to use "KeyFieldName=OrdNo;OrdPos" or something like that? (delimiter komma or semicolon)
Then i tried to set the Property as discribed:
with aCol.Properties as TcxCheckBoxProperties do begin AllowGrayed := False; ValueChecked := True; ValueUnchecked := False; end;
but i cannot find this property in object-inspector.
Can you explain my mistake?
Thank you
Rolf
Hello Rolf,
I created a separate ticket on your behalf: (T984049: How to setup an unbound check box column when using more than one key field). We placed it in our processing queue and will process it shortly.
ok, next thing: I have checkd "MultiSelect" and unchecked "CellMutiSelect"
After checking "CellMultiSelect" and "CellSelect" i can check ONE row - and only one row. But i have to select 5, 10 or 20 rows a time. And after that i will go trougth the selected row to work with the underlaying data.
Have you set the multiselect to persistent Rolf?
no, it is "msmStandard"
but, it dosn't matter, if it is "msmStandard" or "msmPersistent" - always the same behavior.
i changed the datamodell an add a DB-Field - that work fine!
Fair enough, your OptionsSelection needed to be set to
That should work