Board index » delphi » TStringGrid Edit Problem

TStringGrid Edit Problem

I've been forced to use a TStringGrid to display a data structure that I
have because of it's complexity.  The problem I'm having is allowing the
user to make changes to the data in the StringGrid.  There are certain
columns that I want to allow them to edit, and other's not.  I have taken
care of this, but the problem I'm having is when the user does make the
changes, how can I tell they're done making the change, so I can put the
change back into the database?

I have used the OnKeyPress to figure out when the user can and cannot edit a
cell.  But, how can I tell when to save the information back to the
database?  I thought I might be able to use the OnKeyDown and capture the
Enter, Tab & Cursor keys, so when they press any of these, it will save, and
thus, that is when I will write the data back to the file.  But the clincher
comes when the user clicks with the mouse to exit the field.  What then?

The Only other way I can think of is to put the data into the database with
every key stroke.  This doesn't seem very effecient, and I might end up with
a lot of other problems there too.

Is there a better way to do this?  Any ideas are appreciated.  I'm using
Delphi 3.

Jesse

 

Re:TStringGrid Edit Problem


Jesse Castleberry <D...@iThink.net> wrote in article
<6nr226$9j...@news2.ispnews.com>...

Quote
> I've been forced to use a TStringGrid to display a data structure that I
> have because of it's complexity.  The problem I'm having is allowing the
> user to make changes to the data in the StringGrid.  There are certain
> columns that I want to allow them to edit, and other's not.  I have taken
> care of this, but the problem I'm having is when the user does make the
> changes, how can I tell they're done making the change, so I can put the
> change back into the database?
> I have used the OnKeyPress to figure out when the user can and cannot
edit a
> cell.  But, how can I tell when to save the information back to the
> database?  I thought I might be able to use the OnKeyDown and capture the
> Enter, Tab & Cursor keys, so when they press any of these, it will save,
and
> thus, that is when I will write the data back to the file.  But the
clincher
> comes when the user clicks with the mouse to exit the field.  What then?
> The Only other way I can think of is to put the data into the database
with
> every key stroke.  This doesn't seem very effecient, and I might end up
with
> a lot of other problems there too.

There is a way to do it, best done through your own component with
something like an OnCellExit event.
Or you can take the easy way out and find a free component that does it all
for you. I have one. Email me if you want it.

- Graeme Vincent
gvincent @ specialty . co . za

Re:TStringGrid Edit Problem


Quote
Jesse Castleberry <D...@iThink.net> wrote:
> user to make changes to the data in the StringGrid.  There are certain
> columns that I want to allow them to edit, and other's not.  I have taken
> care of this, but the problem I'm having is when the user does make the
> changes, how can I tell they're done making the change, so I can put the
> change back into the database?

The easiest way would be to use an enhanced grid component which has this
functionality build in - like my TStringAlignGrid which has both a
OnAfterEdit event for the resaving to the database as well as the
possibility to set columns to read-only. It's freeware for all Delphi
versions and comes with full source, just look at my homepage.

Bye,
   Andy

--
Andreas H"orstemeier                       | "Wenn ist das Nunstueck git
email: a...@scp.de                         | und Slotermeyer? Ja! Beiherhund
       a...@hoerstemeier.de                | das Oder die Flipperwaldt
www:   http://www.westend.de/~hoerstemeier | gersput."
fido:  2:2452/108     ICQ: 1661968         |                  (Monty Python)

Re:TStringGrid Edit Problem


Quote
>There is a way to do it, best done through your own component with
>something like an OnCellExit event.
>Or you can take the easy way out and find a free component that does it all
>for you. I have one. Email me if you want it.

I have heard of one called "TStringAlignGrid", but I haven't downloaded it
yet.  Is this the one you have?  If not, I would appreciate a copy of what
you have :-).

Thanks,
Jesse

Re:TStringGrid Edit Problem


Quote
>The easiest way would be to use an enhanced grid component which has this
>functionality build in - like my TStringAlignGrid which has both a
>OnAfterEdit event for the resaving to the database as well as the
>possibility to set columns to read-only. It's freeware for all Delphi
>versions and comes with full source, just look at my homepage.

Does this work with Delphi 1?

Thanks,
Jesse

Re:TStringGrid Edit Problem


Quote
Jesse Castleberry <D...@iThink.net> wrote:

[Description of TStringAlignGrid]
Quote
> Does this work with Delphi 1?

Yes, the only version I'm not sure about is Delphi 4, but I hope to be able
to check this soon.

Bye,
  Andy

--
Andreas H"orstemeier                       | ..Our continuing mission:
email: a...@scp.de                         | to seek out knowledge of C,
       a...@hoerstemeier.de                | to explore strange unix
www:   http://www.westend.de/~hoerstemeier | commands, and to boldly code
fido:  2:2452/108     ICQ: 1661968         | where no one has man page 4.

Re:TStringGrid Edit Problem


Hi Jesse,

The way I solved this was to take advantage of the SetEditTextEvent in the  
TStringGrid. First, the primary index of the data is added to a column  
(visible or not) in the TStringGrid when the data is loaded. Then, when  
the SetEditTextEvent is called, the primary index of the record being  
edited is added to a TStringList-object. When the dialog is closed, the  
TStringList-object contains references to all the records that were  
edited. Use LOCATE to find those records in the table and just update ALL  
the fields at once; i.e., don't worry about which fields were actually  
edited.

A few things to keep in mind: if the user edits the same row more than  
once, you don't want to keep adding the same reference to the TStringList.  
And if the user can delete records, then you'll want to have a second  
TStringList which contains references to all of those deleted records.  
It's obvious that any records that are in the deleted list don't need to  
be updated.

Hope this helps.

Regards,

Patrick

Regarding message <6nr226$9j...@news2.ispnews.com>
from <D...@iThink.net> on 06 Jul 98:

Quote
> The problem I'm having is allowing the
> user to make changes to the data in the StringGrid.  There are certain
> columns that I want to allow them to edit, and other's not.  I have taken
> care of this, but the problem I'm having is when the user does make the
> changes, how can I tell they're done making the change, so I can put the
> change back into the database?

Other Threads