The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Programmatically select row in datagrid
Posted: 12 Aug 09 9:29 AM
|
Hi all (again),
In the legacy version of Saleslogix, you could select "edit" from a grid item, make your changes to the window that popped up, click ok, and the item in the grid you just edited would be highlighted still. This would also work when "add"ing an item.
However, in 7.2 (not sure about 7.5, I haven't got that far yet). When you do the same you are returned to the beginning of the list. Also, if you refresh the grid for any reason, you are returned to the beginning of the list and not on the item that was previously highlighted.
Is there any way to programmatically (and quickly) change the row selected on a grid by the unique id of the record on the grid?
I have been using the method outlined below, but this only really works for small datasets as it takes ages for it to step through larger ones row by row. Someone also offered a solution involving ticking the "Sortable" property in the datagrid properties (to load the whole dataset into memory) but this also did not work.
CURRENTLY USING
sub Grid_SelectRowByID (grdGRD, strID)
'*** THIS CRAZY LITTLE FUNCTION LEGS IT THROUGH THE GRID UNTIL IT REACHES THE ITEM WE EDITED. '*** IT SUCKS, BUT IS CURRENTLY THE ONLY WAY TO DO IT.
dim strID_CURRENT dim intROW_CURRENT dim intROW_MAX dim objWSCRIPT
Set objWSCRIPT = Application.CreateObject("WScript.Shell") grdGRD.Refresh intROW_MAX = grdGRD.NodesCount grdGRD.SetFocus Application.DoEvents intROW_CURRENT = 1 strID_CURRENT = grdGRD.GetCurrentField("PRODUCT_CATID") While strID_CURRENT <> strID and intROW_CURRENT <= intROW_MAX objWSCRIPT.SendKeys "{DOWN}" Application.DoEvents strID_CURRENT = grdGRD.GetCurrentField("PRODUCT_CATID") intROW_CURRENT = intROW_CURRENT + 1 WEnd Set objWSCRIPT = Nothing end sub
Come on Raul, you know you're up for a challenge. |
|
|
|
Re: Programmatically select row in datagrid
Posted: 12 Aug 09 9:49 AM
|
I know that there are many issues around the DataGrid between versions, so this may not work on 7.2 (I don't have access to a 7.2 system right now), but it does work on 7.5:
DataGrid.Selection.Add("ROWID")
|
|
|
|
Re: Programmatically select row in datagrid
Posted: 12 Aug 09 10:02 AM
|
I tried it, no error messages, but it doesn't do anything (at all) either. Do I have to do something to the grid first, like tick "Sortable" or something like that? There's nothing in the Developers Ref about it either 
I also put a DataGrid.Selection.Clear in first as well as it is a multiselect grid, and I only want to highlight the one item that was just edited. |
|
|
|
Re: Programmatically select row in datagrid
Posted: 12 Aug 09 10:06 AM
|
If the row is in the immediate view of the grid (ie. you don't have to scroll down to it) your method works. However, if it is outside the immediate viewable area of the grid, it won't select it. I've tried this with "sortable" on and off.
Hmmmmm. |
|
|
|
Re: Programmatically select row in datagrid
Posted: 12 Aug 09 10:33 AM
|
Here is where the difference in version comes into play:
In 7.5 it will work, but requires Sortable.
The whole reason for it is that the data on the Grid isn't completely loaded, thus it cannot find the item to select. When you apply the Sortable property, it will load the whole resultset to be able to sort it, thus allowing you to set the selection past the current set of visible items.
(Additionally, do not select the UseVSSC as it will also cause the grid to not load all the data.
Now, the downside, the grid will be much slower to load and refresh....
|
|
|
|
Re: Programmatically select row in datagrid
Posted: 12 Aug 09 10:48 AM
|
Looks like I'll have to upgrade soon then. Thanks for your help Raul 
If anyone else has managed to get around this in earlier versions please do let me know, to me it seems like it should be a no-brainer that the grid should be able to do this. |
|
|
|
Re: Programmatically select row in datagrid
Posted: 12 Aug 09 10:56 AM
|
Its been tried by many, but your current code is probably as good as it gets.
Another alternative may be to load your query into a Recordset and then attach the recordset to the Grid. Since the whole recordset is available, it may be possible to then set the selected node programatically and have it presented on the screen. |
|
|
|
Re: Programmatically select row in datagrid
Posted: 17 Aug 09 3:46 AM
|
I seem to remember experiencing difficulties with the Selection.Add, which were resolved by adding the key as a field to the layout and making invisible (I think it had to be the first in the layout (before hiding)). I could be wrong, but worth a go.
James |
|
|
|