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.
kyriakos70Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

developmentguruPresidentCommented:
You can respond to the OnCellClick event and set the value in the field in the associated dataset.  If you do this in code and post the changes you will see it in the grid.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LearnDelphiCommented:
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.
0
kyriakos70Author Commented:
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
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

kyriakos70Author Commented:
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);
0
developmentguruPresidentCommented:
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.
0
kyriakos70Author Commented:
developmentguru
Send me the property.

Kyriakos
0
developmentguruPresidentCommented:
try adapting the following

if DBGrid1.Columns[0].Field.Name = 'MyFielName' then
  ;//you are on the right column
0
dabbiXCommented:
What about Colums in Memo
0
developmentguruPresidentCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.