1 (edited by AD1408 2016-10-26 15:35:22)

Topic: Moving tGrid rows

Hi Guys,


I like to move records from one tGrid to another and then move them up-down after move on moved tGrid, similar to MVD save action dialog. Having multi select when moving one tGrid to another would be nice.


In Use tGrid records would be used with relevant comboboxses


Please see the attached sample project.

Post's attachments

Attachment icon Moving tGrid Rows.zip 5.14 kb, 399 downloads since 2016-10-26 

Adam
God... please help me become the person my dog thinks I am.

Re: Moving tGrid rows

Hi Adam,
Not sure if this is the sort of thing that you're meaning for the first part of your post (moving records from one grid to another) but I imagine it will be enough to get you started;  please see attached.
But I'm out of ideas as to how you'd achieve the second part (moving rows up and down).
Derek.

Post's attachments

Attachment icon Moving tGrid Rows.zip 338.88 kb, 395 downloads since 2016-10-27 

Re: Moving tGrid rows

I used Derek's sample and put in the second part (Moving up and down). Hope this is what you are looking for. I added a counter field to your Country table to do this process.

Post's attachments

Attachment icon Moving tGrid Rows (2).zip 585.34 kb, 408 downloads since 2016-10-27 

Re: Moving tGrid rows

Hi Derek,


Thanks for the sample...


The following image may explain better as to what I like to do:


http://s18.postimg.org/c09ylbqnt/tgridrm.png

Its more like third part of search action dialog rather than save action (I mentioned in my first post) of MVD


As said on first post multi select (CTRL+LeftClick, SHIFT+LeftClick, CTRL+A) is desirable before move.


Perhaps Dmitry's help needed on this one.

Adam
God... please help me become the person my dog thinks I am.

Re: Moving tGrid rows

AD1408
Your revised project:

Post's attachments

Attachment icon Moving tGrid Rows_fixed.zip 8.29 kb, 459 downloads since 2016-10-27 

Dmitry.

Re: Moving tGrid rows

Hi Dmitry,


Thank you VERY much.....................................


That's exactly what wanted to do.

Adam
God... please help me become the person my dog thinks I am.

Re: Moving tGrid rows

I added the multi-select to Dimitry's solution.

Post's attachments

Attachment icon Moving tGrid Rows_fixed (2).zip 585.44 kb, 452 downloads since 2016-10-27 

Re: Moving tGrid rows

Thanks a lot ehwagner.............

Great stuff.. that completes the task fully.

Adam
God... please help me become the person my dog thinks I am.

9 (edited by AD1408 2016-10-31 14:47:33)

Re: Moving tGrid rows

Hi Guys,


I was trying to apply Dmitry's code to move up and down part to a project. No errors but couldn't get them moving. Could somebody points out as to what's wrong with the following code please?


procedure Form1_Button3_OnAfterClick (Sender: string);
begin
    UpdateDatabase('component');
end;

procedure frmLookups_Button3_OnClick (Sender: string; var Cancel: boolean);
var
    id1, id2: integer;
    record_count1, record_count2: string;
begin
    if (frmLookups.tgLookupsComponents.SelectedRow > 0) then
    begin
        id1 := frmLookups.tgLookupsComponents.dbItemID;
        id2 := frmLookups.tgLookupsComponents.dbIndexToID(frmLookups.tgLookupsComponents.SelectedRow-1);

        record_count1 := SQLExecute('SELECT record_count FROM component WHERE id='+IntToStr(id1));
        record_count2 := SQLExecute('SELECT record_count FROM component WHERE id='+IntToStr(id2));

        if (record_count1<>'') and (record_count2<>'') then
        begin
            SQLExecute('UPDATE component SET record_count='+record_count2+' WHERE id='+IntToStr(id1));
            SQLExecute('UPDATE component SET record_count='+record_count1+' WHERE id='+IntToStr(id2));
            frmLookups.tgLookupsComponents.dbUpdate;
            frmLookups.tgLookupsComponents.dbItemID := id1;
        end;

    end;
end;

procedure frmLookups_Button4_OnClick (Sender: string; var Cancel: boolean);
var
    id1, id2: integer;
    record_count1, record_count2: string;
begin
    if (frmLookups.tgLookupsComponents.dbItemID <> -1) and (frmLookups.tgLookupsComponents.SelectedRow < frmLookups.tgLookupsComponents.RowCount-1)  then
    begin
        id1 := frmLookups.tgLookupsComponents.dbItemID;
        id2 := frmLookups.tgLookupsComponents.dbIndexToID(frmLookups.tgLookupsComponents.SelectedRow+1);

        record_count1 := SQLExecute('SELECT record_count FROM component WHERE id='+IntToStr(id1));
        record_count2 := SQLExecute('SELECT record_count FROM component WHERE id='+IntToStr(id2));

        if (record_count1<>'') and (record_count2<>'') then
        begin
            SQLExecute('UPDATE component SET record_count='+record_count2+' WHERE id='+IntToStr(id1));
            SQLExecute('UPDATE component SET record_count='+record_count1+' WHERE id='+IntToStr(id2));
            frmLookups.tgLookupsComponents.dbUpdate;
            frmLookups.tgLookupsComponents.dbItemID := id1;
        end;

    end;
end;

I have component component table with two field:
component, type text
record_count, type counter
and table grid named: tgLookupsComponents
checked button numbers and they are correct too.


---------------------------------------------
Edit:
Relevant part of the project attached

Post's attachments

Attachment icon CodeRepository.zip 8.79 kb, 425 downloads since 2016-10-31 

Adam
God... please help me become the person my dog thinks I am.

Re: Moving tGrid rows

AD1408
You forgot to enable sort in the TableGrid by field record_count

Dmitry.

11 (edited by AD1408 2016-11-01 15:21:21)

Re: Moving tGrid rows

Hi Dmitry,


Thank you so much...........


------------------------------------------------
edit:


I made the change as advised and component tgrid move up-down worked fine. I applied the same code to Categories on lookups by changing button numbers and tgrid name but this time didn't work. Unless, I'm missing something else again, looks like something else needs changing.

Post's attachments

Attachment icon CodeRepository 2.zip 9.9 kb, 408 downloads since 2016-11-01 

Adam
God... please help me become the person my dog thinks I am.

Re: Moving tGrid rows

Project fixed. The "category" tablegrid needed to be sorted on record_count. In your "category" move button SqlExecute scripts you were pointing to table "component" instead of "category".

Post's attachments

Attachment icon CodeRepository 2_Fixed.zip 586.95 kb, 428 downloads since 2016-11-01 

Re: Moving tGrid rows

Hi ehwagner,


Thank you so much.........


Missing 'category' was a silly mistake on my part.

Adam
God... please help me become the person my dog thinks I am.

Re: Moving tGrid rows

Sorry to bother you again on this Guys...


My assumption was once tGrid ordering done, they'd show on combobox dropdown in same order, but they are not.
In this case, I was using move up-down in lookups for relevant comboboxes on a different window i.e. Details.


Also, when no record on tGrid selected and user clicks on move up-down buttons, pop-up info message needed to inform users that they need to select a record first like in edit or delete buttons.


Any help on these please......

Post's attachments

Attachment icon CodeRepository3.zip 10.47 kb, 401 downloads since 2016-11-02 

Adam
God... please help me become the person my dog thinks I am.

Re: Moving tGrid rows

AD1408
For the property Filter of ComboBoxes specify:

1=1 ORDER BY record_count


for the popup message

procedure frmLookups_Button3_OnClick (Sender: string; var Cancel: boolean);
var
    id1, id2: integer;
    record_count1, record_count2: string;
begin

    if frmLookups.tgLookupsComponents.dbItemID=-1 then
    begin
        ShowMessage('You should select a record');
        Exit;
    end;

    if (frmLookups.tgLookupsComponents.SelectedRow > 0) then
    begin
.....
Dmitry.

16 (edited by AD1408 2016-11-03 07:03:50)

Re: Moving tGrid rows

Thank you so much Dmitry............


I think I inserted the code in wrong place or incorrectly?


/////////////////////////////////////////////////////////////////////////////////////
/// --> LOOKUPS - COMPONENTS - MOVING ROWS UP and DOWN <--//////////////////////////
/////////////////////////////////////////////////////////////////////////////////////

procedure Form1_Button3_OnAfterClick (Sender: string);
begin
    UpdateDatabase('component');
end;

procedure frmLookups_Button3_OnClick (Sender: string; var Cancel: boolean);
var
    id1, id2: integer;
    record_count1, record_count2: string;
begin
    if (frmLookups.tgLookupsComponents.SelectedRow > 0) then
    begin
        id1 := frmLookups.tgLookupsComponents.dbItemID;
        id2 := frmLookups.tgLookupsComponents.dbIndexToID(frmLookups.tgLookupsComponents.SelectedRow-1);

        record_count1 := SQLExecute('SELECT record_count FROM component WHERE id='+IntToStr(id1));
        record_count2 := SQLExecute('SELECT record_count FROM component WHERE id='+IntToStr(id2));

        if (record_count1<>'') and (record_count2<>'') then
        begin
            SQLExecute('UPDATE component SET record_count='+record_count2+' WHERE id='+IntToStr(id1));
            SQLExecute('UPDATE component SET record_count='+record_count1+' WHERE id='+IntToStr(id2));
            frmLookups.tgLookupsComponents.dbUpdate;
            frmLookups.tgLookupsComponents.dbItemID := id1;
        end;

    end;

    ///When no record selected display info message

procedure frmLookups_Button3_OnClick (Sender: string; var Cancel: boolean);
var
    id1, id2: integer;
    record_count1, record_count2: string;
begin

    if frmLookups.tgLookupsComponents.dbItemID=-1 then
    begin
        ShowMessage('You should select a record');
        Exit;
    end;

    if (frmLookups.tgLookupsComponents.SelectedRow > 0) then
    begin
   /////////
end;


procedure frmLookups_Button4_OnClick (Sender: string; var Cancel: boolean);
var
    id1, id2: integer;
    record_count1, record_count2: string;
begin
    if (frmLookups.tgLookupsComponents.dbItemID <> -1) and (frmLookups.tgLookupsComponents.SelectedRow < frmLookups.tgLookupsComponents.RowCount-1)  then
    begin
        id1 := frmLookups.tgLookupsComponents.dbItemID;
        id2 := frmLookups.tgLookupsComponents.dbIndexToID(frmLookups.tgLookupsComponents.SelectedRow+1);

        record_count1 := SQLExecute('SELECT record_count FROM component WHERE id='+IntToStr(id1));
        record_count2 := SQLExecute('SELECT record_count FROM component WHERE id='+IntToStr(id2));

        if (record_count1<>'') and (record_count2<>'') then
        begin
            SQLExecute('UPDATE component SET record_count='+record_count2+' WHERE id='+IntToStr(id1));
            SQLExecute('UPDATE component SET record_count='+record_count1+' WHERE id='+IntToStr(id2));
            frmLookups.tgLookupsComponents.dbUpdate;
            frmLookups.tgLookupsComponents.dbItemID := id1;
        end;

    end;
    ///When no record selected display info message
 procedure frmLookups_Button4_OnClick (Sender: string; var Cancel: boolean);
var
    id1, id2: integer;
    record_count1, record_count2: string;
begin

    if frmLookups.tgLookupsComponents.dbItemID=-1 then
    begin
        ShowMessage('You should select a record');
        Exit;

    if (frmLookups.tgLookupsComponents.SelectedRow > 0) then
    begin
    //////////
end;

---------------------------------
edit:

Beside above, after applying filter for combo boxes, first one (components) worked but second combo (details) didn't


Attached updated sample project. It doesn't include the latest code for message pop-ups as I couldn't implement it correctly.

Post's attachments

Attachment icon CodeRepository4.zip 11.33 kb, 395 downloads since 2016-11-03 

Adam
God... please help me become the person my dog thinks I am.

Re: Moving tGrid rows

AD1408
Fixed project


But I can't find in which combobox have wrong sort?

Post's attachments

Attachment icon CodeRepository4_fixed.zip 11.53 kb, 447 downloads since 2016-11-03 

Dmitry.

Re: Moving tGrid rows

Thank you so much Dmitry..................


The Category (cbDetailsCategory) combobox is the one not applying sorting.

Adam
God... please help me become the person my dog thinks I am.

Re: Moving tGrid rows

AD1408 wrote:

Thank you so much Dmitry..................


The Category (cbDetailsCategory) combobox is the one not applying sorting.

Checked, cbDetailsCategory also sorted.

Dmitry.

Re: Moving tGrid rows

You forgot to put in "UpdateDatabase('category');"  in your form1_button3_onafterclick.

Re: Moving tGrid rows

Thank you so much ehwagner.............


Now it works fine. I was starting to think something is wrong in my system.

Adam
God... please help me become the person my dog thinks I am.