Link to home
Start Free TrialLog in
Avatar of kyriakos70
kyriakos70

asked on

delphi insert values in a dbgrid cell

Hello,
I have a dbgrid with values cash, payment, vat and total sum.
I want when I click in the cell vat to automatic insert a value in it.
ASKER CERTIFIED SOLUTION
Avatar of developmentguru
developmentguru
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Are you trying to do an automatic calculation in a dbgrid? If so, it makes more sense to create an auto-calc field in your dataset.
Avatar of kyriakos70
kyriakos70

ASKER

developmentguru
How do I choose the right cell for the onclick event? I did something like this but nothing
procedure TForm15.DBGrid2CellClick(Column: TColumn);
var a : real;
begin
if (dbgrid2.Columns.Items[6].FieldName=('¦ ‘'))=true     then
Also I did this but needs expression boolean
if dbgrid2.OnCellClick(dbgrid2.Columns.Items[12])  then
begin
try
a:=(strtofloat(dbgrid2.Columns.Items[6].Field.Value) + strtofloat(dbgrid2.Columns.Items[7].Field.Value) + strtofloat(dbgrid2.Columns.Items[8].Field.Value) + strtofloat(dbgrid2.Columns.Items[9].Field.Value) + strtofloat(dbgrid2.Columns.Items[10].Field.Value) + strtofloat(dbgrid2.Columns.Items[11].Field.Value));
b:=(a*19)/100;
adodataset3.FieldByName('¦ ‘').Value:=  floattostrf(b,ffFixed,7,2);
c:=a+b;
adodataset3.FieldByName('£¥Ÿ›©_šŸœ™£¤¡©').Value:=  floattostrf(c,ffFixed,7,2);
There is a FieldIndex in the TColumn, not sure if that is the exact property name as I am at home now.  If you can't find it let me know and I will look it up.  Test the Column.FieldIndex to make sure you are in the right column.  The dataset is automatically in the right row.  This will work well as long as the user is not allowed to rearrange the rows.  Then you will need to look for a Field property the column is associated with and see if the FieldName is the one you are looking for.  This will allow for switching column order.
developmentguru
Send me the property.

Kyriakos
try adapting the following

if DBGrid1.Columns[0].Field.Name = 'MyFielName' then
  ;//you are on the right column
What about Colums in Memo
You would need to be more specific.  If you mean that you need to update the value of a memo column, one extra line of code to modify the associated column's value would do the trick.  If you mean to have a set of columns within the memo, I would need to know more about whay you are trying to do.