cxGrid_Q31584 cxgrid 拖放移动记录
cxgrid 拖放移动记录,cxgrid 拖放,cxgrid 拖动记录,cxgrid 鼠标拖动记录 这是cxgrid开发公司回复客户时所发送的源码项目,用于实现鼠标拖动记录,改变记录在表格中的位置,所以直接编译运行,供大家借鉴
问题地址:https://www.devexpress.com/Support/Center/Question/Details/Q31584/help-with-drag-and-drop-in-cxgrid-reorder-rows
下载地址:https://www.devexpress.com/Support/Center/Attachment/GetAttachmentFile/e1b941a6-feb1-413e-b7e1-b1c1eece12be
unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
cxDataStorage, cxEdit, DB, cxDBData, cxGridCustomTableView,
cxGridTableView, cxGridDBTableView, DBTables, cxGridLevel, cxClasses,
cxControls, cxGridCustomView, cxGrid, dxSkinsCore, StdCtrls; type
TForm1 = class(TForm)
cxGrid1: TcxGrid;
cxGrid1DBTableView1: TcxGridDBTableView;
cxGrid1Level1: TcxGridLevel;
DataSource1: TDataSource;
Table1: TTable;
cxGrid1DBTableView1ID: TcxGridDBColumn;
cxGrid1DBTableView1Order: TcxGridDBColumn;
cxGrid1DBTableView1Text: TcxGridDBColumn;
Table1ID: TAutoIncField;
Table1Order: TSmallintField;
Table1Text: TStringField;
Button1: TButton;
procedure cxGrid1DBTableView1DragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
procedure cxGrid1DBTableView1DragDrop(Sender, Source: TObject; X,
Y: Integer);
procedure FormCreate(Sender: TObject);
procedure cxGrid1DBTableView1StartDrag(Sender: TObject;
var DragObject: TDragObject);
procedure Button1Click(Sender: TObject);
private
AKeys: Variant;
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.cxGrid1DBTableView1DragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
var
HT: TcxCustomGridHitTest;
begin
with TcxGridSite(Sender) do
begin
HT := ViewInfo.GetHitTest(X, Y);
Accept := (HT is TcxGridRecordCellHitTest) and (TcxGridRecordCellHitTest(HT).GridRecord.RecordIndex <> GridView.DataController.FocusedRecordIndex)
end;
end; procedure TForm1.cxGrid1DBTableView1DragDrop(Sender, Source: TObject; X,
Y: Integer);
var
HT: TcxCustomGridHitTest;
ASourceMinOrderValue,ASourceMaxOrderValue,ADestOrderValue: Variant;
I: Integer;
AController : TcxGridTableController;
AOrderIndex : Integer;
ADataSet : TDataset;
AField : TField;
IsUp : boolean;
ADataController : TcxDBDataController;
begin
AOrderIndex := cxGrid1DBTableView1Order.Index;
with TcxGridSite(Sender) do
begin
HT := ViewInfo.GetHitTest(X, Y);
ADestOrderValue := TcxGridRecordCellHitTest(HT).GridRecord.Values[AOrderIndex];
AController := TcxGridTableController(GridView.Controller);
ADataController := TcxDBDataController(GridView.DataController);
ASourceMinOrderValue := AController.SelectedRows[].Values[AOrderIndex];
ASourceMaxOrderValue := AController.SelectedRows[AController.SelectedRowCount-].Values[AOrderIndex];
ADataSet := ADataController.DataSet;
AField := ADataSet.FieldByName('Order');
IsUp := (ADestOrderValue < ASourceMinOrderValue); ADataSet.First;
for I := to ADataSet.RecordCount - do
begin
ADataSet.Edit;
if IsUp and (AField.AsInteger >= ADestOrderValue) and (AField.AsInteger < ASourceMinOrderValue) then
AField.AsInteger := AField.AsInteger + AController.SelectedRowCount;
if not IsUp and (AField.AsInteger <= ADestOrderValue) and (AField.AsInteger > ASourceMaxOrderValue) then
AField.AsInteger := AField.AsInteger - AController.SelectedRowCount;
ADataSet.Post;
ADataSet.Next;
end; if Not IsUp then
ADestOrderValue := ADestOrderValue - AController.SelectedRowCount + ; for I := to AController.SelectedRowCount - do
begin
TcxDBDataController(GridView.DataController).LocateByKey(AKeys[I]);
ADataset.Edit;
AField.Value := ADestOrderValue + I;
ADataset.Post;
end; end;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
Table1.Open;
end; procedure TForm1.cxGrid1DBTableView1StartDrag(Sender: TObject;
var DragObject: TDragObject);
var
I: Integer;
begin
with TcxGridDBTableView(TcxGridSite(Sender).GridView) do
begin
AKeys := VarArrayCreate([, Controller.SelectedRecordCount - ], varVariant);
for I := to Controller.SelectedRecordCount - do
AKeys[I] := Controller.SelectedRecords[I].Values[cxGrid1DBTableView1ID.Index];
end;
end; procedure TForm1.Button1Click(Sender: TObject);
begin
with Table1 do
begin
DisableControls;
try
First;
while not Eof do
begin
Edit;
FieldValues['Order'] := FieldValues['ID'];
Next;
end;
finally
EnableControls;
end;
end;
end; end.
DFM
object Form1: TForm1
Left =
Top =
Caption = 'Form1'
ClientHeight =
ClientWidth =
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch =
TextHeight =
object cxGrid1: TcxGrid
Left =
Top =
Width =
Height =
Align = alClient
TabOrder =
object cxGrid1DBTableView1: TcxGridDBTableView
DragMode = dmAutomatic
OnDragDrop = cxGrid1DBTableView1DragDrop
OnDragOver = cxGrid1DBTableView1DragOver
OnStartDrag = cxGrid1DBTableView1StartDrag
NavigatorButtons.ConfirmDelete = False
DataController.DataSource = DataSource1
DataController.KeyFieldNames = 'ID'
DataController.Summary.DefaultGroupSummaryItems = <>
DataController.Summary.FooterSummaryItems = <>
DataController.Summary.SummaryGroups = <>
OptionsSelection.CellSelect = False
OptionsSelection.MultiSelect = True
object cxGrid1DBTableView1ID: TcxGridDBColumn
DataBinding.FieldName = 'ID'
Options.Sorting = False
end
object cxGrid1DBTableView1Order: TcxGridDBColumn
DataBinding.FieldName = 'Order'
Options.Sorting = False
SortIndex =
SortOrder = soAscending
end
object cxGrid1DBTableView1Text: TcxGridDBColumn
DataBinding.FieldName = 'Text'
Options.Sorting = False
end
end
object cxGrid1Level1: TcxGridLevel
GridView = cxGrid1DBTableView1
end
end
object Button1: TButton
Left =
Top =
Width =
Height =
Caption = 'Reset Order'
TabOrder =
OnClick = Button1Click
end
object DataSource1: TDataSource
DataSet = Table1
Left =
Top =
end
object Table1: TTable
DatabaseName = '.\'
TableName = 'TestTable.db'
Left =
Top =
object Table1ID: TAutoIncField
FieldName = 'ID'
ReadOnly = True
end
object Table1Order: TSmallintField
FieldName = 'Order'
end
object Table1Text: TStringField
FieldName = 'Text'
Size =
end
end
end
cxGrid_Q31584 cxgrid 拖放移动记录的更多相关文章
- Javascript - ExtJs - GridPanel组件
GridPanel组件(Ext.grid.GridPanel)logogram:Ext.grid.Panel | xtype:gridpanel 此类派生自Ext.Panel,创建表格需要两个必须的对 ...
- 跟我一起学extjs5(19--模块记录的拖放删除、拖放复制新增)
跟我一起学extjs5(19--模块记录的拖放删除.拖放复制新增) 网页其中的拖放(drag-drop)是比較有趣的操作,extjs5中非常好的封装了拖放的动作,也有各种类来支持,可是 ...
- 18、手把手教你Extjs5(十八)模块记录的拖放删除、拖放复制新增
网页当中的拖放(drag-drop)是比较有趣的操作,extjs5中很好的封装了拖放的动作,也有各种类来支持,但是要学好“拖放”这个东西真是很难,特别是象我这样英语不好的人,看不太懂官网上的说明,做一 ...
- 关于Delphi cxGrid主从表中从表只能编辑第一条记录的问题
在Delphi cxGrid主从表中从表只能编辑第一条记录,这个问题是由于设置主从关联字段错误造成的. 从表DBtableView2的keyfieldnames,DetailKeyFieldNames ...
- cxGrid主从表删除从表记录的困惑
cxgrid主从表显示方便直观. varADetailDC: TcxGridDataController;AView: TcxCustomGridTableView; with cxgrdbndtbl ...
- 【html】学习记录-拖放(drag and drop)
目的:实现拖动目标并放置到指定区域. 使元素可拖动,涉及到元素的全局属性draggable <img draggable="true" /> 即img元素设置为可拖 ...
- ExpressQuantumGrid4的cxGrid的一些使用方法和经验
使用cxGrid有一些时间了,在这里总结一下使用cxGrid的一些方法,希望给刚开始接触cxGrid的人一些帮助. 1.简单介绍:cxGrid右下方的cxGrid1Level1是表示Grid表的层,c ...
- cxGrid的使用方法
来源 http://www.cnblogs.com/djcsch2001/archive/2010/07/19/1780573.html 1. 去掉GroupBy栏 cxGrid1DBTable ...
- Delphi CxGrid 汇总(2)
17. 怎样设计多表头的cxGrid? 解决:cxGrid可以解决如下的表头: --------------------------------- | 说明1 | 说明2 | ------------ ...
随机推荐
- [Note] Yet Another Resource Negotiator
Yet Another Resource Negotiator Apache Hadoop YARN 是新一代资源管理调度框架,主要针对 Hadoop MapReduce 1.0 的缺陷做出了改进 M ...
- java碎笔
选择表达式 overviewPart1.setMonth_incom(rs.getString("month_incom").equals("")?" ...
- "No Python interpreter configured for the project " in Pycharm for python selenium
自动化测试问题: pyCharm提示python Interpreter没有设置,点击configure Python Interpreter,进入Settings 在 Project Interpr ...
- redis的密码设置(windows与linux相同)
接着我们昨天的说,昨天redis的启动已经了解,今天来说说redis的密码设置.(不管怎么说redis也是数据库,也需要密码) 修改密码可以2种行径.第一种,直接修改配置文件,打开redis.conf ...
- 修改android 开机画面
对于使用安卓手机的人来说,能够自由定制手机的各种界面是每个用户之所以喜欢安卓系统的最根本的缘由,比如手机的开机界面中的bootanimation.zip文件.本文就如何修改开机界面,做一个简单的流程介 ...
- stm32开发之串口的调试
总的函数如下 void USART1Configuration(void){ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Peri ...
- java.lang.IllegalArgumentException: Document base E:\Eclipse\workspace\.metadata\.plugins\org.eclips
1.错误描述 四月 13, 2015 5:56:55 下午 org.apache.catalina.core.AprLifecycleListener init 信息: The APR based A ...
- weblogic部署web项目出现错误
1.错误描述 <2015-3-15 下午02时13分01秒 CST> <Info> <Security> <BEA-090905> <Disabl ...
- 芝麻HTTP:Python爬虫入门之URLError异常处理
1.URLError 首先解释下URLError可能产生的原因: 网络无连接,即本机无法上网 连接不到特定的服务器 服务器不存在 在代码中,我们需要用try-except语句来包围并捕获相应的异常.下 ...
- I2C总线协议的软件模拟实现方法
I2C总线协议的软件模拟实现方法 在上一篇博客中已经讲过I2C总线通信协议,本文讲述I2C总线协议的软件模拟实现方法. 1. 简述 所谓的I2C总线协议的软件模拟实现方法,就是用软件控制GPIO的输入 ...