Datagrid event call problem

Hi,

I'm using datagrid to show a set of data. The datagrid datasource is from an ado data control (adodc) which recordsource is from an SQL statement declared on form load.

e.g :

datagrid1.datasource = Adodc1
querys1 = "select * from employee"
adodc1.recordsource = querys1
adodc1.refresh

With this I have been able to populate the datagrid accordingly. Now.. to my problems.

I need to have a messagebox pop up everytime a user try to change the value of a column in the datagrid when the "add data" button was not clicked beforehand. No Problem with that.. a messagebox would appear everytime user change the value of a column in the datagrid, by using the beforecolupdate event call.

However, on every execution of the beforecolupdate event call, the new value that the user entered would be replaced by the old value again. Hence, the new value entered are not stored anywhere, and even though the message box appear and user choose to update the data, old data would still appear instead of new data.

My question : is there any event call that comes before beforecolupdate ? Because I have try using the afterColEdit event call but that doesn't get executed before the beforecolupdate event call, and therefore, I couldn't store the old value for further use when doing updating.

Any help please ?

Thanks a lot.
LVL 1
ayufansAsked:
Who is Participating?
 
SpazMODicCommented:
PAQed, with points refunded (250)

SpazMODic
EE Moderator
0
 
GrahamSkanRetiredCommented:
Oldvalue is passed into the procedure
Private Sub DataGrid1_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
0
 
ayufansAuthor Commented:
Hi GrahamSkan,

I'm asking whether there's an event call that can be used BEFORE the beforecoldupdate procedure ? because whenever I ran this procedure, oldvalue would automatically replace the new value, therefore, no update can be performed. Any other suggestions please ??

Thanks
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
ayufansAuthor Commented:
Hi,

I've come up with a solution for my problem. I ended up using the aftercolupdate event call. Storing the new value when this event was called, and then refreshing the datagrid, and stored the oldvalue after the datagrid are filled with old value from the database. After having both value stored on a variable, I then called the update procedure.

Thanks anyway.

I'll have this question posted up on the cleanup TA.

Thanks.
0
 
ayufansAuthor Commented:
Hi,

I have found a solution to my problem. Instead of using the beforecolupdate event call, I use the aftercolupdate event call. After the datagrid is updated (but the database is not yet updated) I store the new value on a variable upon calling the aftercolupdate event call. I then refresh the datagrid causing the old value to show up on the datagrid. Once I did this, I then store the oldvalue in another variable and call the update procedure after that.

Thanks anyway. I'll have this question posted up for deletion on the Community Support TA.

Thanks
0
 
ayufansAuthor Commented:
Yikes... page error when submitting first comment. After reload still have no new comment, so I posted new comment and the previous one shows up. Sorry.

Thanks
0
 
GrahamSkanRetiredCommented:
None from me. Thought because ayufans' solution seems a bit tortuous, I think I still do not understand the question.

Why not make Cancel = True to keep the old data (which could be displayed in the message box)?

If MsgBox("Do you really want to change the data in column " & ColIndex & " from " & OldValue, vbYesNo) = vbYes then
   Cancel = False
Else
   Cancel = True
End If
0
 
ayufansAuthor Commented:
Hi GrahamSkan,

Never thought of using Cancel = True before... :p how does that work anyway ?? I really have no clue about it at all.

Anyway.. here's the whole thing... I'm going to explain it at the best way I can, sorry if there's anything you don't understand because english is not my first language.

I have a datagrid which are populated with ADODC. A query are then binded to that adodc, which results in data filling in the datagrid according to that query.

If a user click the "Add" button, the datagrid.tag properties would have the value of "add", and therefore the datagrid_aftercolupdate event call won't be called, because it look something like this (example is for datagrid2, I have multiple datagrid in one form) :
-------------------------------------------------------------------------------------------------------------------------------------------
Private Sub DataGrid2_AfterColUpdate(ByVal ColIndex As Integer)
    If DataGrid2.Tag <> "add" Then
        i = DataGrid2.Col
        Label41.Tag = DataGrid2.Columns(i).Text
        Label42.Tag = i
        Label43.Tag = DataGrid2.Row
               
        querys2 = "select * from booking_detail where no_bl = '" & Combo2.Text & "' and item = 'T' and exp_imp = '" & Left(Combo1.Text, 1) & "'"
        Adodc2.RecordSource = querys2
        Adodc2.Refresh
        Label12.Tag = "yes"
        Label44.Tag = DataGrid2.Columns(i).Text
       
        Call mnUpdCol_Click
    End If
End Sub
-------------------------------------------------------------------------------------------------------------------------------------------
as you can see.. if the datagrid.tag properties doesn't have the value of "add" nothing would be done. This is because, the user may add data to the datagrid, and after finished inputting data, the update procedure would be called by the click of the "update" button. This update procedure is called "mnUpdCol_Click".

However, I would also like the same procedure to be used, when a user wants to perform update/correction on the data that has been previously entered. By not clicking the "add" button, user would then made changes on the column and if he/she didn't clicked the "update" button, I would call the aftercolupdate button like the one above. As you can see, I store the new value on label41.tag properties, and after refreshing the datagrid, I store the old value (taken from the database which has not yet been updated) on label44.tag properties. After I have both values, I would then call the "mnUpdCol_Click" procedure. On this procedure (which is way too long to post, because it is almost 17 pages long when being copy-pasted in a word document) I would then ask user if they're really sure that they want to update the column or not. If yes, I would update the data with new value, which is stored in the label42.tag properties. If the user choose no, then I would reupdate the database with the old value just to be sure. And that's it.

Previously, instead of using the aftercolupdate event call, I would use the beforecolupdate event call. However, if I use this event call, even before any coding on the event was executed, old value would replace new value on the datagrid itself. e.g :
On column1, the old value is "aaaaa". Once I changed the value of that column into "aaaab", the beforecolupdate event call would be triggered. Previously, this is what the beforecolupdate event looks like :
-------------------------------------------------------------------------------------------------------------------------------------------
Private Sub DataGrid2_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
    If DataGrid2.Tag <> "add" Then
        i = DataGrid2.Col
        Label41.Tag = DataGrid2.Columns(i).Text
        Label42.Tag = i
        Label43.Tag = DataGrid2.Row
        Label44.Tag = OldValue
       
        Call mnUpdCol_Click
    End If
End Sub
-------------------------------------------------------------------------------------------------------------------------------------------
As you can see, I store new value on label41.tag properties and old value on label44.tag properties. Now.. even though I have changed the value of the column on the datagrid, whenever the beforecolupdate event was called, old data would replace new data. In this example the value of "aaaab" would be replaced by "aaaaa" and therefore label41.tag value would be the same as label44.tag value, and even though I call the column update procedure afterwards, there would seem to be no changes made, even though actually on the database old value do get replaced by new value, but because it is the same, the value remain at "aaaaa".

Now, by putting the coding that are previously located on beforecolupdate event to the aftercolupdate event, I can achieve what I initially want, and can perform the update correctly.

I know that this is not the best way of updating the datagrid, but this is the method I use for all of the datagrid in my application. I'm still a very amateur VB programmer and am not developing fast enough, but this way do work for me.

GrahamSkan : your idea of using cancel = True did not occur to me, because like I've said.. I'm pretty much a beginner and therefore do not know a lot of better method compared to the one I'm using.

If there's anything that is not clear, I'd be glad to clarify.

Thanks a lot.
0
 
GrahamSkanRetiredCommented:
It might take me a while to get a full understanding, but meanwhile you might like to know that I thought that English WAS your first language, and I am English (and fussy about the use of language). I couldn't understand why you go up so early in the morning. (It's 08.24 here).
0
 
ayufansAuthor Commented:
GrahamSkan : No it's not ^_^ It's either my second or third language. I can't decide :p And it's like 4 PM (16.00) like here, so it's almost in the evening already ^_^ The time here is +7 GMT ^_^ I'm in the office banging my brain hahaha

Have a good one.

Thanks
0
 
ayufansAuthor Commented:
Hi SpazMODic,

Thanks a lot.
0
 
zorica329Commented:
Hello,

Users of application I am coding would prefer a button DELETE on the form instead of just pressing key delete.  I am working with data grids and every time I select a row and press KEY DELETE row is deleted.  How can I call event that fires when I press KEY DELETE from btnDelete_Click(....)In other words how can I call events from other events.

Thanks,

Zorica329
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.