Move line up/down in datagrid
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Move line up/down in datagrid
Hello
Is it possible to move a line in a datagrid up/down by pressing a button? Can somebody tell me how?
Brg Tue
Is it possible to move a line in a datagrid up/down by pressing a button? Can somebody tell me how?
Brg Tue
Re: Move line up/down in datagrid
Hi.
Use the "dgHiliteLine" property. Check it out in the DataGrid use manual.
Craig Newman
Use the "dgHiliteLine" property. Check it out in the DataGrid use manual.
Craig Newman
Re: Move line up/down in datagrid
Craig being gentle and taking on the role of coach lol.
Re: Move line up/down in datagrid
Mike.
Yes and no. I never take anything for granted with DG's. They scare me.
Craig
Yes and no. I never take anything for granted with DG's. They scare me.
Craig
Re: Move line up/down in datagrid
WHAT? omg lol
Re: Move line up/down in datagrid
I've tried that, then the highlighted line moves, but not the data.dunbarx wrote:Hi.
Use the "dgHiliteLine" property. Check it out in the DataGrid use manual.
Craig Newman
Do you have an example?
Re: Move line up/down in datagrid
What he means is after you figure out which line is hilited you can use the other properties of the data grid to rearrange it.
Re: Move line up/down in datagrid
You mean to change the position of a row of data, rather than the position of the selection. Hmm. The datagrid will have multiple sort options by column. What's to stop a user resorting the grid by a different column value and spoiling your new view? (Ok there are things that can be done to fix this, but what is it that you are trying to achieve?)
Re: Move line up/down in datagrid
It doesn't matter. He wants to use the arrow buttons that he created to move a selected line up or down in the list. The answer is yes you can, but we're trying to help him to learn how to figure it out rather than just writing the code for him.
Last edited by Mikey on Fri Feb 10, 2017 3:15 am, edited 1 time in total.
Re: Move line up/down in datagrid
I want to achieve that I can move the line from one position in the datagrid to another.SparkOut wrote:You mean to change the position of a row of data, rather than the position of the selection. Hmm. The datagrid will have multiple sort options by column. What's to stop a user resorting the grid by a different column value and spoiling your new view? (Ok there are things that can be done to fix this, but what is it that you are trying to achieve?)
It's a running order.
It's only an example, and only in this example, it's sorted by number, but that coul'd be different order, so I can't use any column to order.
Re: Move line up/down in datagrid
Right now I can find the line wich is highlighted...
How do I get further, wich command can I use to move it up or down?
Code: Select all
on mouseUp
put the dgHilitedLines of group "seqGrid" into theLine
end mouseUp
Re: Move line up/down in datagrid
Have you read anything about dgtext?
Re: Move line up/down in datagrid
There is a whole section in the manual on the API for the datagrid. There are at least three different ways, using commands and functions described in that chapter, to do this.
Re: Move line up/down in datagrid
SOLVED
I've finally solved this by reading som different links in the Data Grid API
I've selected the line I want to move Press the up arrow
The selected line and the line above change place
Now pressing the down button
The selected line and the line under change place

I've finally solved this by reading som different links in the Data Grid API
I've selected the line I want to move Press the up arrow
Code: Select all
on mouseUp
## find the line no. of the selcted line, put it in af variable called theLine
put the dgHilitedLines of group "seqGrid" into theLine
put the dgDataOfLine[theLine] of group "seqGrid" into theSelectedRowData
## theDataA is now an array variable.
put the dgDataOfLine[theLine-1] of group "seqGrid" into theSelectedRowAboveData
## theDataC is now an array variable with data from row above.
## Create a nested array.
## dictate values for individual columns
put theSelectedRowData["Nr."] into theRowAboveData["Nr."]
put theSelectedRowData["Data felt 1"] into theRowAboveData["Data felt 1"]
put theSelectedRowData["Data felt 2"] into theRowAboveData["Data felt 2"]
set the dgDataOfIndex[ the dgHilitedIndex of group "seqGrid" - 1 ] of group "seqGrid" to theRowAboveData
## Create a nested array.
## dictate values for individual columns
put theSelectedRowAboveData["Nr."] into theSelectedRowNewData["Nr."]
put theSelectedRowAboveData["Data felt 1"] into theSelectedRowNewData["Data felt 1"]
put theSelectedRowAboveData["Data felt 2"] into theSelectedRowNewData["Data felt 2"]
set the dgDataOfIndex[ the dgHilitedIndex of group "seqGrid" ] of group "seqGrid" to theSelectedRowNewData
## Select the line above.
set the dgHilitedLines of group "seqGrid" to theLine-1
end mouseUp
Code: Select all
on mouseUp
## find the line no. of the selcted line, put it in af variable called theLine
put the dgHilitedLines of group "seqGrid" into theLine
put the dgDataOfLine[theLine] of group "seqGrid" into theSelectedRowData
## theDataA is now an array variable.
put the dgDataOfLine[theLine+1] of group "seqGrid" into theSelectedRowUnderData
## theDataC is now an array variable with data from row above.
## Create a nested array.
## dictate values for individual columns
put theSelectedRowData["Nr."] into theRowUnderData["Nr."]
put theSelectedRowData["Data felt 1"] into theRowUnderData["Data felt 1"]
put theSelectedRowData["Data felt 2"] into theRowUnderData["Data felt 2"]
set the dgDataOfIndex[ the dgHilitedIndex of group "seqGrid" + 1 ] of group "seqGrid" to theRowUnderData
## Create a nested array.
## dictate values for individual columns
put theSelectedRowUnderData["Nr."] into theSelectedRowNewData["Nr."]
put theSelectedRowUnderData["Data felt 1"] into theSelectedRowNewData["Data felt 1"]
put theSelectedRowUnderData["Data felt 2"] into theSelectedRowNewData["Data felt 2"]
set the dgDataOfIndex[ the dgHilitedIndex of group "seqGrid" ] of group "seqGrid" to theSelectedRowNewData
## Select the line under.
set the dgHilitedLines of group "seqGrid" to theLine+1
end mouseUp
Re: Move line up/down in datagrid
Good job figuring it out! Now, a couple of things:
1) Don't mix index code and line code. They are not quite the same thing, and I would hate for you to have some bizarre bug come up later because you mixed them.
2) Click on the bottom row and hit the down arrow. That is called an "edge case". You have to either disable the down button when the user clicks on the bottom row, OR exit the handler for the down button if the bottom row is the row that is selected (or I suppose you could throw up a message to the user, but that isn't very nice). You need to do the same thing for the top row with the up button.
3) Similarly, if the user doesn't select a row, they can still hit the up and down buttons. That edge case also needs to be handled. You can start with the buttons disabled, and only enable them if the user clicks on a row in the DG, or you can just have them not do anything if no row is selected.
4) Your code is more complicated than it needs to be because you are creating an array and then assigning it, when you already have arrays for both rows. Pull the arrays for both rows, then put them into their new positions in the DG array. No new array creation needed.
5) Extra credit: How else could you achieve this, using commands from the API? One of the nifty things about LC is that there are so many ways to write and do the same thing that it is easy to develop your own intuitive style.
6) Extra credit: Did you know that there are other controls, both from LC and from third parties, that you can use to build this sort of list? After you get this working, you should investigate, because depending on what you are trying to do in the end, maybe the DG isn't the ideal way to do it (and maybe it is).
1) Don't mix index code and line code. They are not quite the same thing, and I would hate for you to have some bizarre bug come up later because you mixed them.
2) Click on the bottom row and hit the down arrow. That is called an "edge case". You have to either disable the down button when the user clicks on the bottom row, OR exit the handler for the down button if the bottom row is the row that is selected (or I suppose you could throw up a message to the user, but that isn't very nice). You need to do the same thing for the top row with the up button.
3) Similarly, if the user doesn't select a row, they can still hit the up and down buttons. That edge case also needs to be handled. You can start with the buttons disabled, and only enable them if the user clicks on a row in the DG, or you can just have them not do anything if no row is selected.
4) Your code is more complicated than it needs to be because you are creating an array and then assigning it, when you already have arrays for both rows. Pull the arrays for both rows, then put them into their new positions in the DG array. No new array creation needed.
5) Extra credit: How else could you achieve this, using commands from the API? One of the nifty things about LC is that there are so many ways to write and do the same thing that it is easy to develop your own intuitive style.
6) Extra credit: Did you know that there are other controls, both from LC and from third parties, that you can use to build this sort of list? After you get this working, you should investigate, because depending on what you are trying to do in the end, maybe the DG isn't the ideal way to do it (and maybe it is).