vladman Цитата: А dfm свою бросьте еще
[more=dfm к предыдущему сообщению]object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 385
ClientWidth = 559
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Tree: TdxTreeView
Left = 0
Top = 0
Width = 177
Height = 385
ShowNodeHint = True
Indent = 19
Items.NodeData = {
0101000000250000000000000000000000FFFFFFFFFFFFFFFF00000000050000
00061A043E04400435043D044C04270000000000000000000000FFFFFFFFFFFF
FFFF00000000000000000712043504420432044C042000310027000000000000
0000000000FFFFFFFFFFFFFFFF00000000000000000712043504420432044C04
20003200270000000000000000000000FFFFFFFFFFFFFFFF0000000000000000
0712043504420432044C0420003300270000000000000000000000FFFFFFFFFF
FFFFFF00000000000000000712043504420432044C0420003400270000000000
000000000000FFFFFFFFFFFFFFFF00000000000000000712043504420432044C
0420003500}
Align = alLeft
ParentColor = False
SelectedIndex = -1
TabOrder = 0
OnMouseDown = TreeMouseDown
end
object cxGrid1: TcxGrid
Left = 177
Top = 0
Width = 382
Height = 385
Align = alClient
TabOrder = 1
object View: TcxGridBandedTableView
OnDragOver = ViewDragOver
OnMouseMove = ViewMouseMove
OnMouseUp = ViewMouseUp
NavigatorButtons.ConfirmDelete = False
DataController.Summary.DefaultGroupSummaryItems = <>
DataController.Summary.FooterSummaryItems = <>
DataController.Summary.SummaryGroups = <>
Bands = <
item
Width = 111
end>
end
object cxGrid1Level1: TcxGridLevel
GridView = View
end
end
end[/more]
Добавлено: Цитата: Я как раз об этой ошибке упоминал
Не совсем ошибка - можно дальше таскать band'ы как ни в чем ни бывало. Даже курсор нормальным становится, после того, как в следующий раз при выполнении EndDragAndDrop(FDropAccepted) параметр будет равен true.
Привел немного в порядок доработанный пример:
[more=подробнее...]
// pas
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Graphics, Controls, Forms,
Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
cxStyles, cxCustomData, cxFilter, cxData, cxDataStorage, cxEdit, cxGridCustomView,
cxGridCustomTableView, cxGridTableView, cxGridBandedTableView, cxClasses,
cxGridLevel, cxGrid, ComCtrls, dxtree, Classes, cxGridCommon;
type
TBandHeaderMovingObjectChild = class(TcxGridBandHeaderMovingObject);
TForm1 = class(TForm)
Tree: TdxTreeView;
cxGrid1Level1: TcxGridLevel;
cxGrid1: TcxGrid;
View: TcxGridBandedTableView;
procedure TreeMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ViewDragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
procedure ViewMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure ViewMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
FMovObj: TBandHeaderMovingObjectChild;
FMovBandID: integer;
FDropAccepted: boolean;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.TreeMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
Tree.BeginDrag(false);
end;
procedure TForm1.ViewDragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
// Здесь Sender и Source - (). Не понятно почему.
var band: TcxGridBand;
bandRect: TRect;
bandClientPos: TPoint;
bandScreenPos: TPoint;
headerViewInfo: TcxGridBandHeaderViewInfo;
hitTest: TcxCustomGridHitTest;
begin
if ((State = dsDragEnter) and (Tree.Dragging)) then
begin
Tree.EndDrag(false);
Accept := true;
band := View.Bands.Add;
band.Caption := Tree.Selected.Text;
band.Index := 0;
FMovBandID := band.ID;
headerViewInfo := View.ViewInfo.HeaderViewInfo.BandsViewInfo.Items[band.Index].HeaderViewInfo;
headerViewInfo.State := gcsPressed;
bandRect := headerViewInfo.Bounds;
bandClientPos.X := bandRect.Right - Round((bandRect.Right - bandRect.Left)/2);
bandClientPos.Y := bandRect.Bottom - Round((bandRect.Bottom - bandRect.Top)/2);
hitTest := headerViewInfo.GetHitTest(bandClientPos);
FMovObj := TBandHeaderMovingObjectChild.Create(View.Site);
bandScreenPos := View.Site.ClientToScreen(bandClientPos);
FMovObj.Init(bandScreenPos,hitTest);
FMovObj.CurMousePos := Mouse.CursorPos;
FMovObj.BeginDragAndDrop;
end;
end;
procedure TForm1.ViewMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Assigned(FMovObj) then
begin
FMovObj.CurMousePos := View.Site.ClientToScreen(Point(X,Y));
FMovObj.DragAndDrop(Point(X,Y),FDropAccepted);
end;
end;
procedure TForm1.ViewMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var band: TcxGridBand;
begin
if Assigned(FMovObj) then
begin
// Здесь bag в случае, когда FDropAccepted = false
FMovObj.EndDragAndDrop(FDropAccepted);
if FDropAccepted then
FDropAccepted := false
else
begin
band := View.Bands.FindItemID(FMovBandID);
if Assigned(band) then
View.Bands.Delete(band.Index);
end;
FreeAndNil(FMovObj);
FMovBandID := -1;
end;
end;
end.
// dfm
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 464
ClientWidth = 695
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Tree: TdxTreeView
Left = 0
Top = 0
Width = 185
Height = 464
ShowNodeHint = True
ReadOnly = True
Indent = 19
Items.NodeData = {
0101000000250000000000000000000000FFFFFFFFFFFFFFFF00000000040000
00061A043E04400435043D044C04250000000000000000000000FFFFFFFFFFFF
FFFF00000000000000000612043504420432044C043100250000000000000000
000000FFFFFFFFFFFFFFFF00000000000000000612043504420432044C043200
250000000000000000000000FFFFFFFFFFFFFFFF000000000000000006120435
04420432044C043300250000000000000000000000FFFFFFFFFFFFFFFF000000
00000000000612043504420432044C043400}
Align = alLeft
ParentColor = False
SelectedIndex = -1
TabOrder = 0
OnMouseDown = TreeMouseDown
end
object cxGrid1: TcxGrid
Left = 185
Top = 0
Width = 510
Height = 464
Align = alClient
TabOrder = 1
LookAndFeel.Kind = lfUltraFlat
object View: TcxGridBandedTableView
OnDragOver = ViewDragOver
OnMouseMove = ViewMouseMove
OnMouseUp = ViewMouseUp
NavigatorButtons.ConfirmDelete = False
DataController.Summary.DefaultGroupSummaryItems = <>
DataController.Summary.FooterSummaryItems = <>
DataController.Summary.SummaryGroups = <>
OptionsBehavior.DragFocusing = dfDragOver
Bands = <
item
end>
end
object cxGrid1Level1: TcxGridLevel
GridView = View
end
end
end
[/more]
Огорчает только вид курсора после EndDragAndDrop(false).