JamesP Posted August 24, 2021 Share Posted August 24, 2021 Hello, I am using OnDropRowsEvent for moving rows inside the same Grid. It works nice and smooth. What issue I have got is if you assigned true to DragDrop.Enabled at design time it will always allow you to drag drop, despite I created a button with OnClick where there is a code: uniDBGrid1.DragDrop.Enabled := not uniDBGrid1.DragDrop.Enabled; Changing uniDBGrid1.DragDrop.Enabled at runtime doesn't make any difference. If it was False at design time or OnCreateForm it will always disallow to drag&drop and if True - always allows. Could you please advise how to work it around? Is there some trick to work around? Thank you in advance Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 25, 2021 Share Posted August 25, 2021 9 hours ago, JamesP said: Could you please advise how to work it around? Is there some trick to work around? Hello, Something like this: 1. DragDrop.Enabled in designTime. 2. InRuntime: procedure TMainForm.UniButton1Click(Sender: TObject); begin with UniDBGrid1 do if DragDrop.Enabled then JSInterface.JSCall('getView().findPlugin("gridviewdragdrop").disable', []) //enable end; Quote Link to comment Share on other sites More sharing options...
JamesP Posted August 25, 2021 Author Share Posted August 25, 2021 9 hours ago, Sherzod said: Hello, Something like this: 1. DragDrop.Enabled in designTime. 2. InRuntime: procedure TMainForm.UniButton1Click(Sender: TObject); begin with UniDBGrid1 do if DragDrop.Enabled then JSInterface.JSCall('getView().findPlugin("gridviewdragdrop").disable', []) //enable end; Hi Sherzod, Thank you very much for your help. The solution works fine if you put it on button click event. I am wondering if you can advise me further as there is an issue with initial disabling Drag Drop. I have got an Structure Frame (TUniFrame) that is created at the runtime. It has toolbutton on top, and pageControl with up to 4 TabSheet, that each has a TUniDBGrid. Top Panel has a toolbuttons that switch Edit mode from False to True and from True to False. Initially, Drag&Drop should be disabled as it's readonly mode, but Drag&Drop is allowed, despite I put the code: procedure TStructureLevelFrame.InitDisableDragDropForDBGrid( ADGGrid: TUniDBGrid); begin if ADGGrid.DragDrop.EnableDrag then begin with ADGGrid do JSInterface.JSCall('getView().findPlugin("gridviewdragdrop").disable', []); end; end; I tried put this procedure in many place in my code: OnFrameCreate OnReady Some other procedures that run on load data But it refuses to work, I mean it allows draging rows. Then when I click on button that enable edit mode it switches runs: if DGGrid1.DragDrop.EnableDrag then begin with DGGrid1 do JSInterface.JSCall('getView().findPlugin("gridviewdragdrop").enable', []); end; and then when I end edit mode it runs: if DGGrid1.DragDrop.EnableDrag then begin with DGGrid1 do JSInterface.JSCall('getView().findPlugin("gridviewdragdrop").disable', []); end; After that the drag&drop works as designed. When Read only mode it does not allow drag&Drop and when edit mode it does. Could you please advise where to put procedure InitDisableDragDropForDBGrid for initial disabling when frame is loading on screen? Thank you in advance. Kind Regards Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 25, 2021 Share Posted August 25, 2021 Hi, Can you make a simple testcase to check if possible? Best regards. Quote Link to comment Share on other sites More sharing options...
JamesP Posted August 25, 2021 Author Share Posted August 25, 2021 37 minutes ago, Sherzod said: Hi, Can you make a simple testcase to check if possible? Best regards. Hi Sherzod, When I tried the solution, you provided, on the test project, firstly I put the follow code on OnCreate (form): with UniDBGrid1 do if DragDrop.Enabled then JSInterface.JSCall('getView().findPlugin("gridviewdragdrop").disable', []) //enable That did not work. Then I put the same code on onActivate and it started working. The thing is TUniFrame doesn't have OnActivate, so I do not know what correct place is to put this code for the TUniFrame. The test case would be difficult to create as it dynamically created Frame with data from SQL server. Maybe there is some trick/ jscode that I can use straight after: with UniDBGrid1 do if DragDrop.Enabled then JSInterface.JSCall('getView().findPlugin("gridviewdragdrop").disable', []); Thank you in advance and kind regards. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 25, 2021 Share Posted August 25, 2021 11 minutes ago, JamesP said: The thing is TUniFrame doesn't have OnActivate Hi, Try OnReady event. Quote Link to comment Share on other sites More sharing options...
JamesP Posted August 25, 2021 Author Share Posted August 25, 2021 18 minutes ago, Sherzod said: Hi, Try OnReady event. Hi, I have tried it. It did not work. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 25, 2021 Share Posted August 25, 2021 5 minutes ago, JamesP said: I have tried it. It did not work. Then try ClientEvents, for example: UniDBGrid1 -> ClientEvents -> ExtEvents -> function viewready(sender, eOpts) { if (sender.getView().findPlugin("gridviewdragdrop")) { sender.getView().findPlugin("gridviewdragdrop").disable() } } Quote Link to comment Share on other sites More sharing options...
JamesP Posted August 25, 2021 Author Share Posted August 25, 2021 3 minutes ago, Sherzod said: Then try ClientEvents, for example: UniDBGrid1 -> ClientEvents -> ExtEvents -> function viewready(sender, eOpts) { if (sender.getView().findPlugin("gridviewdragdrop")) { sender.getView().findPlugin("gridviewdragdrop").disable() } } It works, Great. Thank you very much for your help. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.