View Issue Details

IDProjectCategoryView StatusLast Update
0004813JEDI VCL00 JVCL Componentspublic2012-09-10 14:15
ReporterhadAssigned Toobones 
PrioritynormalSeveritytrivialReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.36 
Target VersionFixed in Version3.46 
Summary0004813: TJVDBGrid, TJVDBUltimGrid and mouse wheel
DescriptionTJVDBGrid, TJVDBUltimGrid and mouse wheel:
if the user edits a value in the grid and then rotates wheel
up or down the new value will be lost.
TagsNo tags attached.

Activities

nojoy

2009-06-10 12:03

reporter   ~0015653

This seems to be intended behaviour, see following code snippet:

function [...].DoMouseWheel [...]
begin
  // Do not validate a record by error
  if DataLink.Active and (DataLink.DataSet.State <> dsBrowse) then
    DataLink.DataSet.Cancel;
  Result := inherited DoMouseWheel(Shift, WheelDelta, MousePos);
end;

But i doubt, that this behaviour is what a user expects. Furthermore this code is called before i am able to react on this event. A Dataset.Post in a OnMouseWheel-Function to workaround this, wont help because this would be called after DataSet.Cancel (see above).
I see three possible solutions
1) remove the Cancel-call or replace it with Post
2) make configurable what should happen
3) At least call Dataset.Cancel after the OnMouseWheel-Callbacks
I would prefer solution 1)

obones

2009-07-03 17:16

administrator   ~0015759

Please provide the zipped sources of a sample application showing this

obones

2009-08-04 09:37

administrator   ~0015902

Hello, any news?

R2D2-Master

2009-08-24 08:56

reporter   ~0016012

I fixed this problem by moving the "onmousewheel" event to after the action I change this now everytime I receive a new version of jvcl. All other events happens after the action. I do the following.
In JvDBGrid.pas I change function "DomousewheelUp" and "DoMouseWheelDown".

example before:

function TJvDBGrid.DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean;
var
  Distance: Integer;
begin
  Result := False;
  if Assigned(OnMouseWheelUp) then
    OnMouseWheelUp(Self, Shift, MousePos, Result);
  if not Result then
  begin
    if not AcquireFocus then
      Exit;
    if Shift * KeyboardShiftStates = [ssCtrl] then
      Distance := VisibleRowCount - 1
    else
    if ssShift in Shift then
      Distance := 1
    else
      Distance := 2;
    if DataLink.Active then
      Result := DataLink.DataSet.MoveBy(-Distance) <> 0;
  end;
end;

example after:

function TJvDBGrid.DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean;
var
  Distance: Integer;
begin
  Result := False;
  if not Result then
  begin
    if not AcquireFocus then
      Exit;
    if Shift * KeyboardShiftStates = [ssCtrl] then
      Distance := VisibleRowCount - 1
    else
    if ssShift in Shift then
      Distance := 1
    else
      Distance := 2;
    if DataLink.Active then
      Result := DataLink.DataSet.MoveBy(-Distance) <> 0;
  end;
  if Assigned(OnMouseWheelUp) then
    OnMouseWheelUp(Self, Shift, MousePos, Result);
end;

I do the same to DoMousewheeldown.

Thanks

obones

2009-09-23 17:14

administrator   ~0016170

I'm sorry, but how does this solve the original poster's problem?

obones

2009-12-04 15:36

administrator   ~0016961

Can I get an answer here?

obones

2010-06-07 13:56

administrator   ~0017461

Ah well, no answer, nothing can be done

obones

2010-06-11 16:30

administrator   ~0017488

Reponed per request of the OP

2010-06-14 13:33

 

testjvdbgridbug#4813.zip (4,822 bytes)

nojoy

2010-06-14 13:51

reporter   ~0017489

I have attached a project demonstrating the behaviour (testjvdbgridbug#4813.zip)

steps to reproduce:
-start programm
-change idx from 10 to 11
-change Code10 to xxx
-move mouse wheel

your changes are lost (canceled) and there is no possibility to modify this behaviour.

nojoy

2010-06-14 15:35

reporter   ~0017490

Considering the post of R2D2-Master, I first thought, that his change would allow him to stop the Cancel-call in the OnMouseWheel-Event. But after looking at the source I am nearly sure, that this can not solve the problem.

The events are triggered with this ordering:
JvDbGrid.DoMouseWheel
  -> Dataset.Cancel
  -> TControl.DoMouseWheel
    -> OnMouseWheel
    -> JvDbGrid.DoMouseWheelDown //or Up
      -> OnMouseWheelDown //or Up
      -> Dataset.MoveBy(...)

So no OnMouseWheel-Event can supress the Cancel call nor can a change in DoMouseWheelDown/Up affect DoMouseWheel or Dataset.Cancel.


The DoMouseWheel-Function in TJvDbGrid only seems to be overwritten to produce this bug :). I do not know the original reason for this.
TDBGrid does not behave this way. Pressing KeyUp or PageUp does not behave this way. Therefore I think the Cancel call should be removed.

obones

2010-10-08 16:07

administrator   ~0017815

The reason could be found in the SVN history.
Can you recommend a fix that works for all conditions?

nojoy

2010-10-19 14:02

reporter   ~0017925

>The reason could be found in the SVN history.
I already checked that, but I could not find the reason. This was introduced by r4561 when JvDbGrid.pas was extracted from JvDbControls.pas. As JvDbControls did not contain the relevant code i assume this due to the inclusion of "JvDBGrid additions from Lionel Reynaud".

>Can you recommend a fix that works for all conditions?
My assumption is, that the code was introduced to prevent the situation that someone commits a changed record accidently by moving the mousewheel as already the original comment ("Ne pas valider un record par erreur" ) suggests. If this is true there is no fix that works for all conditions, as this is exactly the opposite of what I think should happen, namely post the record (as TDbGrid does, or PgUp does ...).

What would I recommend: Remove this "functionality" as it is non-standard. (It should be possible to get the same result -throwing away the data- by writing an OnMouseWheel-Event - which is not true for the opposite). But as this change would affect the default behaviour of TJvDbGrid (at least one person thought that this is a feature, not a bug) I would only add this fix for a big update.

obones

2011-06-07 17:26

administrator   ~0018570

Better add a Boolean property to control that behavior
Do you feel like adding this?

stevegr

2011-06-19 11:36

reporter   ~0018777

{*** Use a property ***}

private
  FCancelOnMouseWheel: Boolean;
...

published
  property CancelOnMouseWheel: Boolean read FCancelOnMouseWheel write FCancelOnMouseWheel default False;
...

function TJvDBGrid.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer;
  MousePos: TPoint): Boolean;
begin

  if FCancelOnMouseWheel then begin
    // Do not validate a record by error
   if DataLink.Active and (DataLink.DataSet.State <> dsBrowse) then
      DataLink.DataSet.Cancel;
  end;

  Result := inherited DoMouseWheel(Shift, WheelDelta, MousePos);
end;

stevegr

2011-06-20 16:38

reporter   ~0018790

Updated code: Unit JvDBGrid_2011-06-20.pas

2011-06-20 16:38

 

JvDBGrid_2011-06-20.pas (160,095 bytes)

obones

2012-02-23 10:13

administrator   ~0019492

Fixed in SVN since revision 13085 (2011 07 10)

Issue History

Date Modified Username Field Change
2009-06-06 18:11 had New Issue
2009-06-10 12:03 nojoy Note Added: 0015653
2009-07-03 17:16 obones Note Added: 0015759
2009-07-03 17:16 obones Status new => feedback
2009-08-04 09:37 obones Note Added: 0015902
2009-08-24 08:56 R2D2-Master Note Added: 0016012
2009-09-23 17:14 obones Note Added: 0016170
2009-12-04 15:36 obones Note Added: 0016961
2010-06-07 13:56 obones Note Added: 0017461
2010-06-07 13:56 obones Status feedback => resolved
2010-06-07 13:56 obones Resolution open => suspended
2010-06-07 13:56 obones Assigned To => obones
2010-06-11 16:30 obones Note Added: 0017488
2010-06-11 16:30 obones Status resolved => feedback
2010-06-11 16:30 obones Resolution suspended => reopened
2010-06-14 13:33 nojoy File Added: testjvdbgridbug#4813.zip
2010-06-14 13:51 nojoy Note Added: 0017489
2010-06-14 15:35 nojoy Note Added: 0017490
2010-10-08 16:07 obones Note Added: 0017815
2010-10-19 14:02 nojoy Note Added: 0017925
2011-06-07 17:26 obones Note Added: 0018570
2011-06-07 17:26 obones Status feedback => acknowledged
2011-06-19 11:36 stevegr Note Added: 0018777
2011-06-20 16:38 stevegr Note Added: 0018790
2011-06-20 16:38 stevegr File Added: JvDBGrid_2011-06-20.pas
2012-02-23 10:13 obones Note Added: 0019492
2012-02-23 10:13 obones Status acknowledged => resolved
2012-02-23 10:13 obones Fixed in Version => Daily / SVN
2012-02-23 10:13 obones Resolution reopened => fixed
2012-09-10 14:15 obones Fixed in Version Daily / SVN => 3.46