Ticket Q34130
Visible to All Users

checkbox column as surrogate to DB bound column...

created 17 years ago

Hi,
OK, I have been struggling along on this now for 3 days… time to get
an example from DevExpress to show me how this should really be done…
Here is what I am attempting to do: I want to have an unbound checkbox
column be the "surrogate" to populate a date field. When checked,
today's date goes into the date column. when unchecked, the date is cleared.
This seems pretty straight forward right? It aught to be!
Here is the code that handles drawing the checkbox column:
procedure TfmDesignDB.viewDataSelectCheckBoxCustomDrawCell(Sender:
TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo:
TcxGridTableDataCellViewInfo; var ADone: Boolean);
var v : variant;
begin
  v := AViewInfo.GridRecord.Values[viewDataDefPublishDate.Index];
  if VarIsNull(v) or (v = false) then
     TcxCustomCheckBoxViewInfo(AViewInfo.EditViewInfo).State := cbsUnChecked
  else
     TcxCustomCheckBoxViewInfo(AViewInfo.EditViewInfo).State := cbsChecked;
end;
This code seems to work correctly, and handles null correctly.
Here is the code that is triggered when the user clicks on the checkbox
column:
procedure
TfmDesignDB.cxEditRepositoryDataDefSelectCheckBoxPropertiesEditValueChanged(
Sender:
TObject);
var bChecked : boolean;
    iRecordIndex : integer;
    focusedRecord : TcxCustomGridRecord;
begin
  bChecked := TcxCheckBox(sender).EditingValue;
  iRecordIndex := viewDataDef.DataController.FocusedRecordIndex;
  focusedRecord :=
viewDataDef.ViewData.GetRecordByRecordIndex(iRecordIndex);
  SelectedRowChange(focusedRecord, viewDataSelectCheckBox.Index, bChecked);
end;
SelectedRowchange changes the date column, and that also works correctly.
The problem happens when the user clicks on the checkbox column for a
record where there is already a date and the dataController cache has
just been loaded or reloaded via UpdateItems. In this case the
OnDrawCell code is working correctly and painting a checked checkbox.
But the underlying dataController (I am guessing) the checkbox column is
null. So on the first click, it must be looking back to the
dataController to know what the new value should be. Since it is null,
it returns true. It was already true! It should now be false.
Hmmm, wonder if that made sense… hope so. The bottom line is -
regardless if the column is drawn as checked or not, upon initial load
of the dataController, the value will *always* be null since the
checkbox column is not data-bound. So the first click will always
produce a "true" result even if it is already drawn as checked. So to
make it false, the user actually has to click it twice. The first to go
from null to true. then a second click to go from true to false.
So, can DevExpress please provide an example of an unbound checkbox
column that acts as a surrogate to control a date column? Seems to me,
the "fix" for this would be that I assign values to the DataController's
checkbox column when it loads its cache. But that in itself seems to
have other side effects. Is that even possible?
frustratingly your,
-randall

Show previous comments (2)
DevExpress Support Team 17 years ago

    Hi rs,
    Sorry, but it's impossible to use an unbound column in a data-aware View when the SmartRefresh option is disabled. This is how the DataController works.
    Thanks,
    Dimitros

      Well, if ya tell me it cannot be done, then I'll accept that. But keep in mind, this isn't really a completely unbound checkbox column. It is simply based on a date field. I think a better approach on this problem is to tweak the code that is forcing us to have SmartRefresh turned off.
      thanx
      rs

      DevExpress Support Team 17 years ago

        Hi rs,
        I discussed this problem with our developers and we came to the decision that the current DataController's architecture doesn't allow fixing this behavior. The cause of this is that when the SmartRefresh option is disabled, the Grid handles the underlying dataset's notifications. However, the dataset doesn't pass any information on what exactly was changed. That's why the DataController refreshes all data.
        Thanks,
        Dimitros

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.