Hi Boki
The OnHeaderDblClick that you added in the latest version doesn't really work. The normal DblClick event is still triggered if you double-click on the header. This means that is you have code in OnDblClick, and you also have code in OnHeaderDblClick, BOTH events will fire when you click on the header.
To make matters worse, the OnHeaderDblClick now also has the same problem as the normal DblClick (it doesn't get the second MouseUp if you show a modal form in the OnHeaderDblClick event).
You can fix both these problems like this:
Add a new property to NxCustomGrid called FMouseUpDone.
CODE
TNxCustomGrid = class(TNxCustomGridControl)
private
FColumnDragBox: TColumnDragBox;
FDownDragArrow: TDragArrow;
FDragDropColumn: TNxCustomColumn;
FFooterHintColumn: TNxCustomColumn;
FHeaderHintColumn: TNxCustomColumn;
FLeftResizingGuide: Integer;
FMouseDownColumn: TNxCustomColumn;
FMouseDownPoint: TPoint;
FMouseDownRow: Integer;
FMoveRow: Integer;
//dvn
FMouseUpDone: Boolean;
FOldHeight: Integer;
FOldRowPosition: Integer;
Remove all the code from the DblClick procedure.
CODE
procedure TNxCustomGrid.DblClick;
var
CursorPoint: TPoint;
Column: TNxCustomColumn;
begin
//dvn
{
inherited;
GetCursorPos(CursorPoint);
CursorPoint := ScreenToClient(CursorPoint);
if PtInRect(GetHeaderRect, CursorPoint) then
begin
Column := GetColumnAtPos(CursorPoint);
if Assigned(Column) then DoHeaderDblClick(Column.Index);
end;
}
end;
Change the MouseDown procedure as follows:
CODE
begin
inherited;
FMouseDownPoint := Point(X, Y);
//dvn new
FMouseUpDone := False;
if ssDouble in Shift then Include(FGridState, gtDoubleClicking);
if not(csDesigning in ComponentState) and (GetParentForm(Self).Active)
and Visible and Enabled then SetFocus;
if Columns.Count = 0 then Exit;
case Button of
mbLeft, mbRight:
begin
if (Button = mbRight) and (gtMultiSelect in GridState) then Exit;
if (goHeader in Options) and PtInRect(GetHeaderRect, Point(X, Y)) then
begin
FSizeProgressColumn := GetColumnSizeGripAtPos(X, Y);
end;
if Assigned(FSizeProgressColumn) then { resizing }
begin
with Canvas, FSizeProgressColumn do
begin
if ssDouble in Shift then
begin
BestFitColumn(FSizeProgressColumn.Index);
FSizeProgressColumn := nil;
Exit;
end;
Include(FGridState, gtColumnResizing);
FSizeDelta := 0;
RealLeft := Left;
if FSizeProgressColumn.Position >= FixedCols then Dec(RealLeft, HorzScrollBar.Position);
if Index = 0 then FLeftResizingGuide := RealLeft else FLeftResizingGuide := RealLeft - 1;
FRightResizingGuide := RealLeft + Width - 1;
Pen.Mode := pmNot;
Polyline([Point(FLeftResizingGuide, 0), Point(FLeftResizingGuide, ClientHeight)]);
Polyline([Point(FRightResizingGuide, 0), Point(FRightResizingGuide, ClientHeight)]);
Pen.Mode := pmCopy;
end;
end else
begin
case GetGridArea(Point(X, Y)) of
gaBody: BodyMouseDown;
gaHeader: ClickOnHeader;
gaIndicator: IndicatorMouseDown;
gaInput: ClickOnInput;
gaFooter: ClickOnFooter;
else begin
ApplyEditing;
EndEditing;
end;
end;
if gtIndicatorMouseDown in GridState then BodyMouseDown;
//dvn new start
if gtDoubleClicking in FGridState then
begin
//call mouseup now so we don't miss it if DblClick shows a modal form
MouseUp(Button, Shift, X, Y);
FMouseUpDone := True;
//check if mouse in header
if PtInRect(GetHeaderRect, FMouseDownPoint) then
begin
Column := GetColumnAtPos(FMouseDownPoint);
if Assigned(Column) then
begin
DoHeaderDblClick(Column.Index);
RefreshColumn(Column,gaHeader);
end;
end
else
inherited DblClick;
end;
//dvn new end
end; { else }
end; { mbLeft, mbRight }
end; { case }
end;
Change the MouseUp procedure as follows:
CODE
begin
inherited;
//dvn new
if FMouseUpDone then
Exit;
FDownColumn := FMouseDownColumn;
FMouseDownColumn := nil;
FMouseDownPoint := Point(-1, -1);
if gtRowMoving in GridState then
begin
NearestRow := GetNearestRow(FMouseDownRow, X, Y);
if FMouseDownRow < NearestRow then Dec(NearestRow);
if CanMoveRow(FMouseDownRow, NearestRow) then
etc, etc, ..............
Now the grid will always get the second MouseUp after a DblClick. The gridstate will be normal and all event (like column sorting etc.) will work fine. The "real" MouseUp when the mouse button is released for the second time (after DblClick) will be ignored, because MouseUp has laready been called.
Also, the DblClick will only be called for double-clicks on the grid, and the OnHeaderDblClick will only be called for double-clicks on the header.
Thanks
Deon