Anda di halaman 1dari 22

Editing a table in cxGrid

Version 1.0
05.11.2008
Author: Alen Markov

Version History
Version
1.0

Date
05.11.2008

Name
AMA

Description
Initial Version

INHALT
1

Question....................................................................................................................... 3
1.1
1.2

Testtable ................................................................................................................................................. 3
4 Components for accessing the DB with that table .............................................................................. 4
1.2.1 TDataSource.................................................................................................................................. 4
1.2.2 TIBQuery........................................................................................................................................ 5
1.2.3 TIBDatabase .................................................................................................................................. 6
1.2.4 TIBTransaction............................................................................................................................... 7
1.3 cxGrid - DataController - Datasource ..................................................................................................... 8
1.4 Defining the columns which the cxGrid should display .......................................................................... 8
1.5 Making cells editable ............................................................................................................................ 12
1.6 Display .................................................................................................................................................. 13
1.7 Problem ................................................................................................................................................ 14

Solution ...................................................................................................................... 15
2.1
2.2

Replace TIBQuery through TIBDataset................................................................................................ 15


TIBDataSet ........................................................................................................................................... 16
2.2.1 SelectSQL.................................................................................................................................... 16
2.2.2 Datenmengen Editor .................................................................................................................... 18

Editing a table in cxGrid / Notes by Alen Markov

Seite 2

Question

I want to be able to edit a normal table in cxGrid.

1.1

Testtable

On the Firebird server I created a simple Testdatabase

And inserted 2 records

Editing a table in cxGrid / Notes by Alen Markov

Seite 3

1.2

4 Components for accessing the DB with that table

Nun habe ich ein cxGrid auf's Formular gelegt. Damit die Tabelle im Grid angezeigt wird, habe ich die
markierten 4 Komponenten auf's Formular gelegt:

The properties of that 4 components are:


1.2.1

TDataSource

Editing a table in cxGrid / Notes by Alen Markov

Seite 4

1.2.2

TIBQuery

The property "SQL" from TIBQuery:

Editing a table in cxGrid / Notes by Alen Markov

Seite 5

1.2.3

TIBDatabase

Property DatabaseName: LOGO20:E:\Drive_i\LtxNummer\Daten\LTXNUMMER.GDB


Property Params:

Editing a table in cxGrid / Notes by Alen Markov

Seite 6

1.2.4

TIBTransaction

Editing a table in cxGrid / Notes by Alen Markov

Seite 7

1.3

cxGrid - DataController - Datasource

So the cxGrid knows which data has to be displayed, we have to choose here the DataSource:

1.4

Defining the columns which the cxGrid should display

Editing a table in cxGrid / Notes by Alen Markov

Seite 8

Editing a table in cxGrid / Notes by Alen Markov

Seite 9

Editing a table in cxGrid / Notes by Alen Markov

Seite 10

Editing a table in cxGrid / Notes by Alen Markov

Seite 11

1.5

Making cells editable

Um jetzt im Grid Daten editieren zu knnen, habe ich noch diese Properties auf TRUE gesetzt:

Editing a table in cxGrid / Notes by Alen Markov

Seite 12

1.6

Display

The Grid is now showing the table:

Clicking in a cell, the cell is marked:

Editing a table in cxGrid / Notes by Alen Markov

Seite 13

Klicking on the same cell again, the cursor shows up - it seems like it's possible now to edit the cell

1.7

Problem

The Problem is:


The cell is NOT editable!
(If you try to type something, nothing shows up in the cell! The value can NOT be changed!)

Editing a table in cxGrid / Notes by Alen Markov

Seite 14

Solution

2.1

Replace TIBQuery through TIBDataset

Das TDataSource zeigt jetzt auf das IBDataSet1:

IBDataSet1 is a TIBDataSet and the property "Database" shows on "IBDatabase1":

(The rest is the same as shown in the question above...)

Editing a table in cxGrid / Notes by Alen Markov

Seite 15

2.2

TIBDataSet

2.2.1

SelectSQL

TIBDataSet also has a property "SelectSQL" (I inserted here the same SQL as I did before in TIBQuery).
Setting the property ACTIVE to TRUE, the cxGrid is already showing the table:

Editing a table in cxGrid / Notes by Alen Markov

Seite 16

Note: At this moment, the properties


- DeleteSQL
- InsertSQL
- ModifySQL
- RefreshSQL
are all still empty...
Compiling the whole thing, it looks the same as with the TIBQuery before:
The cells are still NOT not ediable!
(also note that in the Navigator the Buttons like "+" and "-" are disabled)

Editing a table in cxGrid / Notes by Alen Markov

Seite 17

2.2.2

Datenmengen Editor

To make the cells in the cxGrid ediable (and that the navigator Buttons "+" and "-" become enabled),
it was necessary to do this (sorry, just have the german version - but it should be clear with the screenshots):

Auf "Tabellenfelder lesen" klicken:

Editing a table in cxGrid / Notes by Alen Markov

Seite 18

That way the SQL Statements are automatically created:

Editing a table in cxGrid / Notes by Alen Markov

Seite 19

Editing a table in cxGrid / Notes by Alen Markov

Seite 20

Looking now in the objectinspector at the properties


- DeleteSQL
- InsertSQL
- ModifySQL
then the above created SQL statements can be found in them now, for example:

Editing a table in cxGrid / Notes by Alen Markov

Seite 21

Don't forget to set the property ACTIVE now to TRUE again.


In the preview of the cxGrid you can alredady see that the navigator buttons "+" and "-" are enabled now:

And the cells are now editable:


(When you change the value of a cell this way, the database is automatically updated!)

Editing a table in cxGrid / Notes by Alen Markov

Seite 22

Anda mungkin juga menyukai