Jump to content

uniDBGrid DragDrop.Enabled does not work at runtime


JamesP

Recommended Posts

 

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

Link to comment
Share on other sites

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;

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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()
    }
}

 

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...