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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid/adodc weirdness

Status
Not open for further replies.

AdaHacker

Programmer
Sep 6, 2001
392
US
I am totally stumped. I'm posting this on the off chance that someone has seen this before. This problem is a little hard to explain, since it's so weird, but here goes.

I have a form that I use for both displaying and editing data from an Access97 database. I use a datagrid bound to an ADO data control, along with a bunch of plain old text boxes (not bound to the DC) to display the data. When I open the form for displaying data, I open the database with a static cursor, lock read-only, and everything works as it should. When I open it for editing, the only thing I change (besides enabling a few command buttons, which don't come into play anyway) is the way I open it, usually keyset cursor, lock optimistic, although I've tried other ways.
The odd part is that when I do that, the very first element in the first row of the datagrid comes up blank. There is no Earthly reason why this should be happening. I have checked the database to make sure there's data in that field. I have traced the execution to make sure that I wasn't inadvertently changing anything. It all seems to check out.

What's really odd is that I can update that field from my program and then exit the editing form and go back in with the viewing form (these are the exact same form, just opening the database differently in the from load) and the data is there. But if I go back to edit it, it's in the textbox (and therefore in the recordset), but not the datagrid. If I change records or exit and come back in again, the data is gone completely, i.e. the recordset shows null in that field. I'm not running any updates and I've tried setting the datagrid's AllowUpdate property to false.

Does anyone have any clue what could be going on here? I've got basically the same setup on several other forms, and it works perfectly. But on this one form, the problem is consistent. Could it be some obscure property setting? Any reason it would affect only that one cell?
 
Hacker,
I discovered the same problem a couple of years ago. MS provides a sample database tool in Visual Studio that would have been a really convenient tool for us just the way it comes, but alas, with some data sources, the first cell of the first row consistently came up blank. I talked pretty extensively with a wizard at MS, and she finally came to the conclusion that there really was a problem with the datagrid/ADODC, and said they would fix it in a subsequent release. I don't know if they ever fixed it or not, but I have not had the problem in any programs I have written in the past year or so.

Are you at SP 5?

Good Luck,
Paul
 
Paul,
Thanks for responding! I guess a problem with the control would explain things. To answer your question, I am using SP5, so I guess they haven't quite fixed it yet.
When you experienced this problem, did you find any good way of getting around it? I was thinking of writing some ad hoc code in the Form_Load that would save the value in the problem field and restore it in the Form_Unload, keeping the data from being lost, which is what's important. Did you come up with anything better than that?
Thanks again!
AdaHacker
 
A colleague helped me find a solution to my problem, so I thought I'd post in in case anyone else stumbles across this bug.
It turns out that on my form, I had the TabIndex of the datagrid set to zero. This was causing the first entry in the first cell to get focus when the form loaded. For some reason, this appears to have been preventing the cell from getting loaded, or clearing the cell, or something. When I changed records, the recordset was apparently getting updated. Of course, I had the AllowUpdate property of the datagrid set to false, so you would think it shouldn't have been possible for the grid to update the recordset - but it did.
I changed the TabIndex property from zero to 11, and now everything works perfectly. Setting the TabStop property to false also works. Go figure.
 
Yo Hacker,
Thanks for the update! In answer to your question, I never did find a work-around, and apparently just lucked into avoiding the problem by accidentally not having a datagrid as the first control on any forms. Sometimes being lucky is just as good as being good.:)

I printed your response and put it in my "Tips and Tricks" file.

Good job.

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top