Jump to content

Help with DBGrid!


sicoobcooplivre

Recommended Posts

I'm setting up a dbgrid for users to launch daily activities.
Natively, if the user is in the last column and presses right, it will automatically go to the next record.
The same happens if he is in the first column and he presses the left key, he automatically goes back a record.
I want to lock it in the record, and only go to the next record if he presses down arrow, or go to the previous record if he presses up.
Sorry I can't explain it right.
Can you help?

Link to comment
Share on other sites

@sicoobcooplivre

Test this approach:

function cellkeydown(sender, td, cellIndex, record, tr, rowIndex, e, eOpts)
{
    if (e.event.key == "ArrowRight") {
        currPos = sender.getOwnerGrid().getSelectionModel().getCurrentPosition();
        if (sender.getOwnerGrid().getColumns()[currPos.column].isLastVisible == true) {
            sender.getOwnerGrid().getSelectionModel().setCurrentPosition({row: currPos.row, column: sender.getOwnerGrid().getVisibleColumnManager().getFirst().getIndex()});
            sender.getOwnerGrid().getNavigationModel().setPosition(currPos.row, sender.getOwnerGrid().getVisibleColumnManager().getFirst().getIndex());
            return false
        }
    } else if (e.event.key == "ArrowLeft") {
        currPos = sender.getOwnerGrid().getSelectionModel().getCurrentPosition(); 
        if (sender.getOwnerGrid().getColumns()[currPos.column].isFirstVisible == true) {
            sender.getOwnerGrid().getSelectionModel().setCurrentPosition({row: currPos.row, column: sender.getOwnerGrid().getVisibleColumnManager().getLast().getIndex()});
            sender.getOwnerGrid().getNavigationModel().setPosition(currPos.row, sender.getOwnerGrid().getVisibleColumnManager().getLast().getIndex());
            return false
        }
    }       
}

 

Link to comment
Share on other sites

Taking advantage of this topic, I have one more doubt, please can you help:

I'm using the RowWidget option in the Grid to display some registry sub-items.
Is there a possibility that when the user clicks on the + (RowWidget) I collect all that are already open to keep open only the RowWidget of the record that he clicked on?

Thanks!

Link to comment
Share on other sites

1 hour ago, sicoobcooplivre said:

One more doubt: in the form show, it would be possible to focus on a certain column of the grid, because I need that when the user enters the form, he already gives the direct focus on column 2.

You can just use:

procedure TMainForm.UniDBGrid1AfterLoad(Sender: TUniCustomDBGrid);
begin
  (Sender as TUniDBGrid).CurrCol := 2;
end;

 

Link to comment
Share on other sites

I need to execute the + click (rowwidget) of the registry programmatically.
I have an include item button, where I want to execute the + (rowwidget) from the button, so that the user can start typing the selected data.
I just need to run the + (rowwidget) programmatically!

Sorry I can't explain it right, I'm learning!
Thank you for your attention!

exemple.png

Link to comment
Share on other sites

9 hours ago, sicoobcooplivre said:

I need to execute the + click (rowwidget) of the registry programmatically.
I have an include item button, where I want to execute the + (rowwidget) from the button, so that the user can start typing the selected data.
I just need to run the + (rowwidget) programmatically!

Try this approach.

1. UniDBGrid1.ClientEvents.ExtEvents ->

function afterrender(sender, eOpts)
{
    sender._toggleSelectedRow = function() {
        if (sender.getPlugin('rowWidget')) {
            sender.getPlugin('rowWidget').toggleRow(
                sender.getSelectionModel().getCurrentPosition().rowIdx,
                sender.getSelectionModel().getSelected().items[0]
            )
        }
    }
}

2. Usage ->

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  with UniDBGrid1.JSInterface do
    JSCall('_toggleSelectedRow', [])
end;

 

8 hours ago, sicoobcooplivre said:

I searched but couldn't find it!

For example, there was this post:

 

  • Upvote 1
Link to comment
Share on other sites

  • 1 month later...
On 2/8/2023 at 5:52 AM, Sherzod said:

@sicoobcooplivre

Test this approach:

function cellkeydown(sender, td, cellIndex, record, tr, rowIndex, e, eOpts)
{
    if (e.event.key == "ArrowRight") {
        currPos = sender.getOwnerGrid().getSelectionModel().getCurrentPosition();
        if (sender.getOwnerGrid().getColumns()[currPos.column].isLastVisible == true) {
            sender.getOwnerGrid().getSelectionModel().setCurrentPosition({row: currPos.row, column: sender.getOwnerGrid().getVisibleColumnManager().getFirst().getIndex()});
            sender.getOwnerGrid().getNavigationModel().setPosition(currPos.row, sender.getOwnerGrid().getVisibleColumnManager().getFirst().getIndex());
            return false
        }
    } else if (e.event.key == "ArrowLeft") {
        currPos = sender.getOwnerGrid().getSelectionModel().getCurrentPosition(); 
        if (sender.getOwnerGrid().getColumns()[currPos.column].isFirstVisible == true) {
            sender.getOwnerGrid().getSelectionModel().setCurrentPosition({row: currPos.row, column: sender.getOwnerGrid().getVisibleColumnManager().getLast().getIndex()});
            sender.getOwnerGrid().getNavigationModel().setPosition(currPos.row, sender.getOwnerGrid().getVisibleColumnManager().getLast().getIndex());
            return false
        }
    }       
}

Hello,

I'd like to modify the above code so that the user stops at the last column and doesn't go to the first when pressing "ArrowRight".
Similarly, so that the user stops on the first column and doesn't go to the last one when pressing "ArrowLeft".

Could you please help me?

/Delphi 10.4 UniGUI 1.90.0.1549 Complete - Professional Edition/

Link to comment
Share on other sites

Hello,

7 hours ago, Tenare said:

I'd like to modify the above code so that the user stops at the last column and doesn't go to the first when pressing "ArrowRight".
Similarly, so that the user stops on the first column and doesn't go to the last one when pressing "ArrowLeft".

Could you please help me?

function cellkeydown(sender, td, cellIndex, record, tr, rowIndex, e, eOpts)
{
    if (e.event.key == "ArrowRight") {
        currPos = sender.getOwnerGrid().getSelectionModel().getCurrentPosition();
        if (sender.getOwnerGrid().getColumns()[currPos.column].isLastVisible == true) {
            return false
        }
    } else if (e.event.key == "ArrowLeft") {
        currPos = sender.getOwnerGrid().getSelectionModel().getCurrentPosition(); 
        if (sender.getOwnerGrid().getColumns()[currPos.column].isFirstVisible == true) {
            return false
        }
    }       
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...