Board index » delphi » Moving to a cell in TStringGrid

Moving to a cell in TStringGrid

Hi there,

    I have a string grid which has data that is off the screen, so the user
can use the verticla scroll bar to get to the desired row(s), however I have
a combo box above it holding all the unique entries in the grid, obviously
one can assume there are duplicates.  When the user chooses an element from
the combo I set the grid.selection and it does the selction, this sucks as
if the new  selection is off the screen it doesn't go to it.

There must be some simple thing to do this, I looked at FocusCell which is a
protected method within TCustomGrid, but I can't get to it for some reason?

Any ideas anyone???

TIA
Colin B

 

Re:Moving to a cell in TStringGrid


TstringGrid has a property named TopRow. set it to the line number you want
to display as first visible line

LeftCol can be used the same way to set the first visible column.

Denis

Re:Moving to a cell in TStringGrid


In article <1002131611.6129.0.nnrp-01.c1ed1...@news.demon.co.uk>, "Colin

Quote
Basterfield" <col...@areagem.demon.co.uk> writes:
>    I have a string grid which has data that is off the screen, so the user
>can use the verticla scroll bar to get to the desired row(s), however I have
>a combo box above it holding all the unique entries in the grid, obviously
>one can assume there are duplicates.  When the user chooses an element from
>the combo I set the grid.selection and it does the selction, this sucks as
>if the new  selection is off the screen it doesn't go to it.

>There must be some simple thing to do this, I looked at FocusCell which is a
>protected method within TCustomGrid, but I can't get to it for some reason?

Use TopRow to set the grid position in the scroll.

I don't know how you are getting the list of unique column cells, but a
relatively simple way is to rely on the properties of TStringList. Create a
TStringList and set its Sorted to true and Duplicates to dupIgnore. Then assign
the Cols[n] (which is a TStrings) to it. Then call ComboBox.Assign(My
StringList). The sorted list of unique cells in column[n] is now in the
combobox.

Knowing that Cols is a string list you can get the Row of the first occurence
with SelRow := Cols[n].IndexOf(ComboBox.Items[ComboBox.ItemIndex]) and assign a
Rect cast to a TGridRect to the Selection, finally call TopRow := SelRow - 1 to
scroll the stringgrid to see the selection.

Sounds more complex than it is - about 10 lines of code <g>.

Alan Lloyd
alangll...@aol.com

Re:Moving to a cell in TStringGrid


Hi Alan,

    Sorry I didn't explain that bit very well, I am using the grids purely
as a window onto a List inherited from TObjectList, and this particular one
is a list of bookings, where for every booking there could be one or more
rows in the grid, so the combo just holds a list of bookings, hence within
the combo they are unique, but in the llist there are potentially more than
one and my code nees to go to the first of them.

Many thanks for your help, it is appreciated.
Colin B

Quote
"AlanGLLoyd" <alangll...@aol.com> wrote in message

news:20011003165111.18107.00000442@nso-fs.aol.com...
Quote
> In article <1002131611.6129.0.nnrp-01.c1ed1...@news.demon.co.uk>, "Colin
> Basterfield" <col...@areagem.demon.co.uk> writes:

> >    I have a string grid which has data that is off the screen, so the
user
> >can use the verticla scroll bar to get to the desired row(s), however I
have
> >a combo box above it holding all the unique entries in the grid,
obviously
> >one can assume there are duplicates.  When the user chooses an element
from
> >the combo I set the grid.selection and it does the selction, this sucks
as
> >if the new  selection is off the screen it doesn't go to it.

> >There must be some simple thing to do this, I looked at FocusCell which
is a
> >protected method within TCustomGrid, but I can't get to it for some
reason?

> Use TopRow to set the grid position in the scroll.

> I don't know how you are getting the list of unique column cells, but a
> relatively simple way is to rely on the properties of TStringList. Create
a
> TStringList and set its Sorted to true and Duplicates to dupIgnore. Then
assign
> the Cols[n] (which is a TStrings) to it. Then call ComboBox.Assign(My
> StringList). The sorted list of unique cells in column[n] is now in the
> combobox.

> Knowing that Cols is a string list you can get the Row of the first
occurence
> with SelRow := Cols[n].IndexOf(ComboBox.Items[ComboBox.ItemIndex]) and
assign a
> Rect cast to a TGridRect to the Selection, finally call TopRow := SelRow -
1 to
> scroll the stringgrid to see the selection.

> Sounds more complex than it is - about 10 lines of code <g>.

> Alan Lloyd
> alangll...@aol.com

Re:Moving to a cell in TStringGrid


Denis,

    Many thanks for that, cool!

Colin B

Quote
"Denis Jeanroy" <denj...@hrnet.fr> wrote in message

news:9pfst5$qnt$1@reader1.fr.uu.net...
Quote
> TstringGrid has a property named TopRow. set it to the line number you
want
> to display as first visible line

> LeftCol can be used the same way to set the first visible column.

> Denis

Other Threads