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!
|
|
Select grid row through code
Posted: 02 Nov 06 7:19 AM
|
fiogf49gjkf0d I know this is a basic question, but how can I programatically select a specific row in a grid? I have looked and just can't figure it out.
Thanks,
Dave |
|
|
|
Re: Select grid row through code
Posted: 02 Nov 06 7:31 AM
|
fiogf49gjkf0d You need to have the KEYFIELD property set to the unique field of the table that the grid is attached to. That field needs to be present in the grid layout. Whether it is visible or not is up to you.
Then you can say
grdMyGrid.Selection.Add strID
unless I've missed something, that should do it. |
|
|
|
Re: Select grid row through code
Posted: 02 Nov 06 10:32 AM
|
fiogf49gjkf0d John's suggestion is spot on, however, I wanted to add a couple of points. The ability to select a row programatically IIRC was introduced in version 6.2, so in pre-6.2 versions you'll be out of luck.
Secondly, you have to add the table's primary key column to the grid. The table's primary key field will be accessible by default with the grid, but that is not enough, you have to add the field to the layout and then hide it - otherwise you can't set or read the selected rows since it relies on this column being in the grid's layout.
-Ryan |
|
|
|
Re: Select grid row through code
Posted: 02 Nov 06 2:34 PM
|
fiogf49gjkf0d I tried this but it doesn't appear to be actually selecting the entire row in the grid. What I would like is as if i selected the row with my mouse.
Dave |
|
|
|
Re: Select grid row through code
Posted: 02 Nov 06 2:43 PM
|
fiogf49gjkf0d Originally posted by David Saggio
I tried this but it doesn't appear to be actually selecting the entire row in the grid. What I would like is as if i selected the row with my mouse |
|
Not sure I follow. When you say "it doesn't appear to be selecting the entire row" what do you see is happening?
Using
grdMyGrid.Selection.Add strPrimaryID
is the way to select a row. Also, if you want it to have the appearance that the entire row is selected (and not just some cell) then make sure the RowSelect property is set to true. |
|
|
|
Re: Select grid row through code
Posted: 02 Nov 06 4:50 PM
|
fiogf49gjkf0d Here is the way that I am testing for each item in the grid:
grdMyGrid.Selection.Add KEYFIELDID strCrntRecord = grdMyGrid.GetCurrentField("KEYFIELDID") msgbox strCrntRecord
This just keeps displaying the first record in the grid. |
|
|
|
Re: Select grid row through code
Posted: 02 Nov 06 5:54 PM
|
fiogf49gjkf0d AFAIK GetCurrentField doesn't play well with the Selection collection, but it's been a while since I tested that. The Selection collection was added mostly for multi-select functionality. So adding to the Selection collection (which is the only way to select a row) assumes (albeit incorrectly) that multiple rows are, or could be, selected - which GetCurrentField doesn't work for. Know what I mean? BTW, I'm not saying that this doesn't suck, because it does.
BTW, does it visibly select the row in the grid? Or does it just not return the expected values when using GetCurrentField? |
|
|
| |
|
Re: Select grid row through code
Posted: 03 Nov 06 2:17 PM
|
fiogf49gjkf0d Selection does NOT work unless multiselect is enabled. You could say that the GetCurrentField and Selection methods are polar opposites. I've never been able to use both on one datagrid before but that may just be me. |
|
|
|