Programmatically Selecting a Row or Cell in a DataGrid
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Programmatically Selecting a Row or Cell in a DataGrid
Hi,
In setting up an in-house manufactured product, my system automatically adds a new row to a data grid, which is a previously listed component of the manufactured product, re-listed, with a new code that combines the codes of both the manufactured product and the component product, to create a 'hybridcode'. This product, the hybridcode, has to be selected by the system to present a series of queries, the answers to which will be entered into the component products cells, relating to cut sizes and quantities, to arrive at a cost.
My problem is that I cannot programmitically select the row containing the hybridcode (which is referrable, in a field "hybridcode") to allow the user to seamlessly input the required information. This row will always be the last row (the last created) of the DG, which may offer an easy solution (which I haven't been able to arrive at). Any help would be most welcome and appreciated..
In setting up an in-house manufactured product, my system automatically adds a new row to a data grid, which is a previously listed component of the manufactured product, re-listed, with a new code that combines the codes of both the manufactured product and the component product, to create a 'hybridcode'. This product, the hybridcode, has to be selected by the system to present a series of queries, the answers to which will be entered into the component products cells, relating to cut sizes and quantities, to arrive at a cost.
My problem is that I cannot programmitically select the row containing the hybridcode (which is referrable, in a field "hybridcode") to allow the user to seamlessly input the required information. This row will always be the last row (the last created) of the DG, which may offer an easy solution (which I haven't been able to arrive at). Any help would be most welcome and appreciated..
Re: Programmatically Selecting a Row or Cell in a DataGrid
Hi CAsba,
after you have added a new line, doe this:
Best
Klaus
after you have added a new line, doe this:
Code: Select all
...
put the dgNumberOfLines of grp "your dg here..." into tLines
set the dgHilitedLines of grp "your dg here..." to tLines
...
Best
Klaus
Re: Programmatically Selecting a Row or Cell in a DataGrid
Exactly what Klaus says - to select any line in a datagrid, use:
just be aware than if you have code in the data grid's on selectionChanged pHilitedIndex, pPreviouslyHilitedIndex handler to do something when a line is highlighted, this will not fire when you programmatically change lines, so you need manage whatever action was in selectionChanged programmatically as well.
S.
Code: Select all
set the dgHilitedLine of group "<data grid name>" to <integer>
S.
Re: Programmatically Selecting a Row or Cell in a DataGrid
Hi Klaus and Stam,
Again, many thanks for your response.
Klaus, your solution worked perfectly, an easy method to hilite the last line.
Stam, I'm guessing the integer is the index - or line number - of the DG. I would have to know that first; is there a way to determine the line number of a line containing a particular code ?
Again, many thanks for your response.
Klaus, your solution worked perfectly, an easy method to hilite the last line.
Stam, I'm guessing the integer is the index - or line number - of the DG. I would have to know that first; is there a way to determine the line number of a line containing a particular code ?
Re: Programmatically Selecting a Row or Cell in a DataGrid
... is there a way to determine the line number of a line containing a particular code ?
Code: Select all
put lineoffset("your code here...",the dgtext of grp "your dg here") into tLineIamLookingFor
Re: Programmatically Selecting a Row or Cell in a DataGrid
Not sure I understand; but just in case:CAsba wrote: ↑Fri Apr 21, 2023 4:25 pmHi Klaus and Stam,
Again, many thanks for your response.
Klaus, your solution worked perfectly, an easy method to hilite the last line.
Stam, I'm guessing the integer is the index - or line number - of the DG. I would have to know that first; is there a way to determine the line number of a line containing a particular code ?
You can get or set either the dgHilitedLine or the dgHilitedIndex.
The line from index and viceversa with the dgLineOfIndex and the dgIndexOfLine.
If you want to see which index is in which line in the IDE, you can use the property inspector panel switch to custom properties and select “dgCache” from the dropdown menu and you’ll get the array which populates the grid (with the index) and the order these indexes appear in (ie the index for each line).
Hopefully this helps with your question…
S.
Re: Programmatically Selecting a Row or Cell in a DataGrid
Mmm, what I was looking for was a way to programmitacally select a line, not knowing its index, but with reference only to a cell in a column named 'code'.
Re: Programmatically Selecting a Row or Cell in a DataGrid
See above...
To be a bit more precise:
I leave the neccessary error checking to you.
To be a bit more precise:
Code: Select all
...
## put the known content of your column "code" into a variable e.g. tCode
## then:
put lineoffset(tCode,the dgtext of grp "your dg here") into tLineIamLookingFor
set the dghilitedlines of grp "your dg here..." to tLineIamLookingFor
...
Re: Programmatically Selecting a Row or Cell in a DataGrid
Or alternatively:
Put the dgData if the data grid into an array and use
tArray will then contain only the the array elements that fulfill the search, including their numerical indices. So the keys of tArray will contain all the indices you’re searching for, 1 per line.
To get the line corresponding to each index, see dgLineOfIndex as I mentioned above.
Just an alternative approach…
HTH
S.
Put the dgData if the data grid into an array and use
Code: Select all
Filter elements of rArray where each [<“name of key”>] contains “<the text to search for>”
To get the line corresponding to each index, see dgLineOfIndex as I mentioned above.
Just an alternative approach…
HTH
S.
Re: Programmatically Selecting a Row or Cell in a DataGrid
Many thanks, and I now have line I wanted to select selected, which is great ! My next step is to edit the column 'Cost' by inserting the field fld "totalcost" into that cell, which I thought would be easy (mistakenly). I've tried many variations that I've looked up, and some I've tried to 'invent', but without success; so I have to shamelessly ask for help once more. In a nutshell, how do I programmatically edit the contents of the column 'cost', in the selected row by inserting the field "totalcost". Please..
Re: Programmatically Selecting a Row or Cell in a DataGrid
Et voila:
Code: Select all
...
put fld "totalcost" into tNewCost
## Will also work the same way with dgHilitedLines and dgDataOfLine
put the dgHilitedIndex of grp "your dg..." into tIndex
## Now get the data array of that index:
put the dgDataOfIndex[tIndex] into tArray
## Update column -> cost
put tNewCost into tArray["cost"]
## And write the data back into that index:
set the dgDataOfIndex[tIndex] to tArray
...
Re: Programmatically Selecting a Row or Cell in a DataGrid
Hi Klaus,
Thanks
BUT
With this code
I got ann error at
'Expression: bad factor, char 8'
Any ideas ?
Thanks
BUT
With this code
Code: Select all
put fld "totalcost" into tNewCost
## Will also work the same way with dgHilitedLines and dgDataOfLine
put the dgHilitedIndex of grp "datagrid 3" into tIndex
## Now get the data array of that index:
put the dgDataOfIndex[tIndex] into tArray
## Update column -> cost
put tNewCost into tArray["cost"]
## And write the data back into that index:
set the dgDataOfIndex[tIndex] to tArray
Code: Select all
put the dgDataOfIndex[tIndex] into tArray
Any ideas ?
Re: Programmatically Selecting a Row or Cell in a DataGrid
Oops, sorry, foregot to add "... of grp "datagrid 3"!
Made in a hurry...
This will work:
Made in a hurry...
This will work:
Code: Select all
...
put fld "totalcost" into tNewCost
## Will also work the same way with dgHilitedLines and dgDataOfLine
put the dgHilitedIndex of grp "datagrid 3" into tIndex
## Now get the data array of that index:
put the dgDataOfIndex[tIndex] of grp "datagrid 3" into tArray
## Update column -> cost
put tNewCost into tArray["cost"]
## And write the data back into that index:
set the dgDataOfIndex[tIndex] of grp "datagrid 3" to tArray
...
Re: Programmatically Selecting a Row or Cell in a DataGrid
Thank you so much, Klaus - you're a lifsaver !