Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please Help with Data Grid 1

Status
Not open for further replies.

Ferlin

Programmer
Jan 18, 2001
71
US
Hello All,

I have an application with a Datagrid (dgMileage) that I am using to record business trips in. I am using a data base class so I am not using an ADODC, but setting the Datasource myself. Everything works great with the Datagrid except one thins I'm having problems trying to figure out how to do. If you could help me with this I would be greatly appreciative.

Here is what I am trying to do, I have a Column called MILES and one called AMOUNT, I also have a variable called curAmountPerMile that's a Currency that contains the Amount the Company pays it's employees per mile.

When I click on the last Row with the * by it and start keying in the data when I get to the MILES column and key in the number of miles, I would like to take that amount and multiply it by the curAmountPerMile variable and place the answer into the AMOUNT Column.

Example: I key 100 into the MILES Column cell and the curAmountPerMile variable is set to .50, I would like to have the application place 50.00 into the AMOUNT Column cell.

How do I get the 100 out of the MILES Column Cell, and how do I set the AMOUNT column Cell. Everything I've tried so far returns an Invalid Bookmark :-( error , this row is not in the Recordset yet, because your not finished keying it in, so HOW can you set a BookMark on it?

PLEASE HELP, any help would be appreciated Thanks in advance.

Ferlin.
 
Use the DataGrid1_AfterColEdit() event to retrieve the full value you entered into the grid (not partial while ur typing). This should take care of the Invalid Bookmark error. AfterColEdit fires when the current cell loses focus. If you still need more help lemme know...

~Mike
Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
MikeCox,

Thanks, that is where I have been trying to do this at here is the last thing I tried with the same error. I have tried it with the .Text property as well, MSDN talks about CellValue and CellText but they REQUIRE BookMarks.

Private Sub dgMileage_AfterColEdit(ByVal ColIndex As Integer)

If ColIndex = 3 Then
dgMileage.Columns("AMOUNT") = (dgMileage.Columns("MILES") * curAmountPerMile)
End If

End Sub

What am I doing wrong?

Thanks in advance Ferlin.
 
Strange, I just threw this together and it works on my machine. Give it a try on yours, it's almost exactly what you had above:
----------------------------
Option Explicit

Private Const curAmountPerMile As Currency = 0.50

Private Sub DataGrid1_AfterColEdit(ByVal ColIndex As Integer)
If ColIndex = 3 Then
DataGrid1.Columns("AMOUNT").Text = DataGrid1.Columns("MILES").Text * curAmountPerMile
End If

End Sub

-----------------------

I'm using Ado for my connection, but it shouldn't make a difference cuz we're coding against the grid here, not a connection or data environment...

Lemme know how it works.

~Mike Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
Mike,

That was the very first way I tried it, but I just tried it again and it still tells me Invalid Bookmark, here is the routine cut and pasted:

Private Sub dgMileage_AfterColEdit(ByVal ColIndex As Integer)

If ColIndex = 3 Then
dgMileage.Columns("AMOUNT").Text = (dgMileage.Columns("MILES").Text * curAmountPerMile)
End If

End Sub

If I press debug and hold the cursor over AMOUNT it tells me dgMileaage.Columns(&quot;AMOUNT&quot;).Text=<Invalid Bookmark> and the same thing if I hold the cursor over MILES.

The reason the ColIndex=3 is I have 3 more columns in front, a destination, arrival and departure date. So MILES is the 4th Column and AMOUNT is 5th (0 based of course).

I am running VB6.0 Enterprise Edition with SP4 if that might be part of the problem, don't know, been fighting this for about 3 days now.

Don't understand why it works on your and not mine? It's driving me CRAZY....X-)
 
The only thing different between my environment and yours (besides your SP4 and my SP5) is the DB connection (my Adodc1 vs. your DataSource), so that's what I'm inclined to blame at this point. Is your connection strictly at the table level or are you SQL querying the DB to show in the grid at run time? If you're using a query, try dgMileage.ReBind afterward, or Set dgMileage.DataSource = MyDataSource.

Here's what MSDN has to say about this error:

&quot;Invalid bookmark (Error 40027)
An invalid bookmark value was passed to rdoResultset.Move.
To avoid this error, be sure to pass a valid bookmark. Retrieve the bookmark by using rdoResultset.Bookmark, and make sure the variable you use to store the bookmark is still valid.&quot;

Here's its definition of bookmark:

&quot;bookmark
A system-generated value identifying the current row that is contained in an rdoResultset object's Bookmark property. If you assign the Bookmark property value to a variable and then move to another row, you can make the earlier row current again by assigning the value of the variable to the Bookmark property.&quot;

This tells me that another thing you might look for is identical records in the table. DAO (using the Data1 control) could distinguish between two identical records in the same table, but Ado will throw &quot;specified row could not be located...&quot; error if there's not some sort of unique identifier in the table, which could be similar to the bookmark error ur getting.

When you comment out the error code and change a value in the grid, does the DB get updated without any issues? If the grid is bound to a valid DataSource, it should. Your grid code looks good, I think if all else fails you can drop an Adodc1 on the form to verify the DB isn't corrupt or something really crazy. I'll keep thinking of other things to try and let u know what I come up with.

~Mike
Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
MikeCox,

Well, thanks for your help so far. I'm not sure what is going on, but I can't seem to get past that Invalid Bookmark error when using a class for my datasource. I did it just like they said in the MSDN Library on the topic entitled Using the DataGrid Control with a Class Module.

I can drop an Adodc on the form and use it and all runs perfect no problems. Just for <GRINS :-D and GIGGLES LOL> I installed SP5 but that made no difference. Seems like the Class should work just as well as the Ado Data Control, but guess not.

Since my Class is using a Recordset open on the SQL database I'm using in the Adodc, any changes made to the Database by the Data Control should be reflected in my recordset (correct?) I hope.

Maybe I'll just set the Visible property to false on the Adodc and let things go from there, may be my only solution for now.

Later.

Ferlin.
 
Yes, any changes you make to the Adodc1.Recordset will be reflected in the database IF you call Adodc1.Recordset.Update after making your changes to the field values. The exception is if you're using bound controls (like the datagrid), in which case the database is updated when the user changes a value in a cell, then selects a different field or record. Ex:

Adodc1.Recordset.Fields(&quot;MyFieldName&quot;).Value = MyNewValue
Adodc1.Recordset.Update

Good luck!

~Mike
Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top