• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 888
  • Last Modified:

Add and Edit records on DBGrid

Hi all,

Is it possible to Add and Edit records on the DBGrid itself?

If yes, how please?

Thanks

0
error77
Asked:
error77
  • 5
  • 2
  • 2
  • +3
2 Solutions
 
ThommyCommented:
DGrid always displays data from a dataset (Tclientdataset, e. g. a table, a text file) which is connected through a datasource.

Adding and editing records always affects data of the underlying dataset...
0
 
ThommyCommented:
0
 
error77Author Commented:
So, can it be done or not?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Mahdi78Commented:
If you mean add TEdit in DBGrid, so
Yes, you can
0
 
error77Author Commented:
Well, I'm using KDBGrid, which has all that:

http://www.tkweb.eu/en/delphicomp/kcontrols.html

but even if it was a normal dbgrid, how can I edit a cell manually?

0
 
Mahdi78Commented:
I didn't use this component, but if KDBGrid is ReadOnly by default you could switch ReadOnly property to false
0
 
error77Author Commented:
I've check and it hasn't got a radonly property :o/
0
 
Gani2001Commented:
Hi There;

Yes you can,

Use UpdateSQL Component to update Your DBGrid Content.
But you have to write SQL Statments to do :
Delete
Insert
Modfiy

Your Application Must have :
1-DBGrid   ReadOnly  = False
2-Query Component
3-UpdateSQL Component

Best Regards
Abdel
0
 
error77Author Commented:
KDBGrid does not have a readonly property :o/ Also, I want to edit the cell manually not by code.

Is this not possible?
0
 
Ephraim WangoyaCommented:

It is possible

Make sure the Dataset is not in readonly mode
ADOTable1.ReadOnly := False;

Set your Datasoure to AutoEdit
Datasource1.AutoEdit := True;

If all these are set, the grid will automatocally allow you to edit the data by just clicking on a cell and typing


If the the datasource.autoedit is false, then you must use code to invoke editing or addition
To add a new record call  ADOTable1.Append;
To edit the current record call ADOTable1.Edit;

0
 
jimyXCommented:
Am not sure about the KDBGrid, but the normal DBGrid it is  very possible just make sure the properties of the DBGrid is set properly:
ReadOnly = False
under Options -> dgEditing = True

Please note it depends on some other things like if the DBComponent is set to ReadOnly or whether you are using Table or Query even the structure of you Database itself might prevent you from editing the DB records in the DBGrid.
0
 
error77Author Commented:
Mixed both solutions and it worked. Thanks very much!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now