More Datagrid Problems...

Extremebfn
10-21-2004, 12:40 AM
Ok. One of my main problems was that if i delete a record from a Datagrid by using the mouse to select it and then pressing the delete key, i got a error.This was fixed by adding a Primary Key to my table which was connected to the datagrid.

Now my next problem: The program is a Quotation program. So here is how the program works.

1. The user selects a product from a Combo box and clicks on a ADD Buton.

2. The selected product is added to a Table(QuoteDetailSection).

3. The Datagrid is set to that Table,so after the add i use a Datagrid.Refresh to display the newly added records to the Table inside the datagrid.

4. The Totals and Tax amount is displayed inside a Textbox just below the Datagrid. This values are updated when the tables containts change.

Ok...so the obove steps work 100%. But what about the Delete? I client want to be able to remove a item from the quote.Ok...so this is done my using the mouse to select the Row in the datagrid..and pressing the delete key. Cool...so this works...but NOW! My problem is to update the new Totals and Tax values.

I placed my function that Calcualates the new Values in the AfterDelete Funtion of the Datagrid...but then i still shows the amount without deducting the deleted item. So what i did i ran the program in debug mode(F8) and when steps by step.When it gets to the AfterDelete Funtion and calls the CalculateNewTotals Function, i went into my database(Access) and the Deleted item was still their.It only gets deleted after the AfterDelete funtion...so it kinda deletes SLOW? what can this be??

MKoslof
10-21-2004, 07:02 PM
Can you show us your code where you implement these calculations and deletions?

Extremebfn
10-22-2004, 07:54 AM
Can you show us your code where you implement these calculations and deletions?

Sure...the code for the calculations i will post, but for the deletion i can becuase as i said: I use the mouse to select the row i want to delete in the datagrid, and then i just press the delete key on the keyboard...so i have no CODE for the deletion.Is this wrong?

VisualBrat
10-22-2004, 08:34 AM
Sure...the code for the calculations i will post, but for the deletion i can becuase as i said: I use the mouse to select the row i want to delete in the datagrid, and then i just press the delete key on the keyboard...so i have no CODE for the deletion.Is this wrong?


If you are using a table that has the datagrid info stored each time, you will have to implement code to remove the record from the table.

I have a similar program and this is how I delete the records:

1.) I have a label above the Datagrid that says double click on any item to delete it. ....you can use whatever event.

2.) The event above will show a message box that says "Are you sure you want to delete this record?"

3.) If yes is chosen, I implement the following code:

Set Data = OpenDatabase(App.Path + "\" + "DATABASE.MDB")
SQL = ""
SQL = "SELECT * FROM TABLENAME where FIELDNAME ='" & datagrid.Col(x) & "' "
Set rs = Data.OpenRecordset(SQL)
Do Until rs.EOF
rs.Delete
rs.MoveNext
Loop
Set rs = Nothing
Datagrid.Refresh
msg = MsgBox(datagrid.col(X) & " HAS BEEN DELETED")

This works for me.

: )

Extremebfn
10-26-2004, 03:55 AM
HI. I think your idee is going to work 100%. I just wanna know?

What is die X Variable? Datagrid.Col(x)?

How do i know what value X must have?

Thnx for your input.... :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum