Re-select current record after TA refill.

FreeriderUK

Well-known member
Joined
Jun 27, 2006
Messages
100
Location
London
Programming Experience
10+
Hi all,

I'm using a DataGridView to show a list of customers from an AccessDB.

When I save any changes, the TableAdapter is re-filled and the currently selected customer is reset to the first in the list.

What is the best way to ensure I go back to re-select the customer I previously selected.

I know I can do it by searching through the DGV to find the customer name or whatever, but this would be quite slow.
Is there a quicker way to do it?
 
Hi all,

I'm using a DataGridView to show a list of customers from an AccessDB.

When I save any changes, the TableAdapter is re-filled and the currently selected customer is reset to the first in the list.
Aside from the fact that you don't fill a tableadapter with anything, why would you execute a Fill after an Update?


What is the best way to ensure I go back to re-select the customer I previously selected.
Don't do the refill. Do you close and reopen every word document after you save? How about closing the web browser and opening a new one and returning to the forum listing and picking your thread after you make a post here?

Hopefully you can see the logic of not doing either of these things; it's the same logic that tells us that downloading the same data from a db that we just uploaded is nonsensical
 
Are you saying, the only time you ever fill a dataset is when you first start the program?

you don't fill a tableadapter with anything
You just couldn't resist it could you? ;)

...why would you execute a Fill after an Update?
I'm doing it because the dataset also includes calculated fields based on dates. When these dates are changed, the order the data is presented in needs to be refreshed too.
I don't know how to get this result without refilling the dataset...

How about closing the web browser and opening a new one...
Well, I would consider clearing the cache and refreshing the page contents to make sure I had the newest information.
 
Are you saying, the only time you ever fill a dataset is when you first start the program?
I fill them when I need to - this doesnt necessarily happen at program start :)

You just couldn't resist it could you? ;)
Of course not :p

I'm doing it because the dataset also includes calculated fields based on dates. When these dates are changed, the order the data is presented in needs to be refreshed too.
I don't know how to get this result without refilling the dataset...
Mmmm... *Tweaks beard* well this kind of op has been needed ever since databases began so facilities have evolved over time to allow an insert/update query to calculate some values, insert/update them and simultaneously pass them back to the client. I use a real DB (Oracle) and I've experienced SQLServer do this properly too. There has been some recent chatter that Access doesnt do this properly, but older memory serves that it can. As I've never used Access I don't really have a comment but hopefully youre not using a **** database like this..


Well, I would consider clearing the cache and refreshing the page contents to make sure I had the newest information.
You do that every time you post?
 
As I've never used Access...
But you slag it off at every opportunity! :eek:

hopefully youre not using a **** database like this..
Well, yes I am :eek:. I'm comfortable with it. I know it's not supposed to be a *real* database but it's just a database - I'm not doing anything complicated with it.

Surley, what I'm trying to do, doesn't depend on which database I use - the fact it works OK if I refill the DataSet shows it can do all I want it to.

The problem is I'm such a crap programmer, I can't find a way of "jumping" to a particular record in the DataSet (or should that be BindingSource):)
I even know the CustomerID I wnat to jump to, so why can't I do it!!??
 
Well, yes I am :eek:. I'm comfortable with it. I know it's not supposed to be a *real* database but it's just a database - I'm not doing anything complicated with it.
There is also SQL Ce that is installed with and is far better integrated with VS2008, plus it scales better up to Sql Express and the full Sql Server. I looks to me it could be replacing Access as standalone file-based db for devs/people that otherwise don't need Access.
 
Do some reading on DataView.Find
I think the way to do it will be using the CustomersBindingSource.Find
The problem is, the DataSource for CustomersBindingSource is ADifferentBindingSource.

I keep getting the error:
VB.NET:
DataMember property 'CustomerID' cannot be found on the DataSource.

Does anyone know what it means?

I'm using this code:
VB.NET:
TbCustomersBindingSource.Position = TbCustomersBindingSource.Find(RMSDataSet.Tables("tbCustomers").Columns("CustomerID").ToString, "14")
 
I found the following info last night, and it seems to explain the problem.

When you drag an item from the child table to a form, it automatically creates the BindingSource. When it does this, it sets the DataSource property for the BindingSource to the wrong value. All you have to do is select the FKbindingsourcename from the list of available DataSource values for the property.

The link to the original post is: BindingSource.Find() Problem - MSDN Forums

I tried the suggestion and the code in my previous post works.

Now to check it didn't break something else...
 
But you slag it off at every opportunity! :eek:
Specifically, never used it with VS2005/ADO.NET. It's in active use at every company I've ever been at, and it's persistently been the thorn in everyone's side. It gets slagged off because it deserves it ;) though I should really add that people use it in environments it was not intended for. Once you step beyond using Access (remembering that it is a front end to the Jet DB engine) which was coded by MS - a company that knows all Jet's faults

I'm not doing anything complicated with it.
I'd say that uploading a record, have the DB calculate an ID and have that ID returned in the same operation is actually a bit more complicated than Jet was designed for; you'll note that in Access, data edits are done online, whereas ADO.NET does these things offline. User clicks New Record on an access form and they get a new record prepopulated with the next ID already

I'm dimly aware that Jet supports stored procedures (or soemthing like a stored procedure) that can possibly be used to achieve your goal, but if youre looking at a multi-user database, I implore you to use a proper one, like SQLServer Express, CE or OracleXE
 
ps; you may find that filling to another table, and then manually updating the ID allows your position to be retained
 
How to retain the record pointer position after refilling a dataset...

All that and you didn't even give the man the answer?!? I swear this is why I hate forums sometimes...all you need is a little help with something and they come out of the wood work to tell ya how wrong you are but NO ONE has an answer either! Unbelievable! :mad:

Here is one way to get your record pointer back to it's original position after a refill of a dataset/datatable.

*********************CODE SNIPPET***********************
Public Sub SetRecordPointerAfterDataRefresh()

Dim ptCurrentCell As Point = YourDataGridView.CurrentCellAddress

' do your refresh of data

' now reset the current cell

YourDataGridView.CurrentCell = YourDataGridView.Rows(ptCurrentCell.Y).Cells(ptCurrentCell.X)

End Sub

*********************CODE SNIPPET***********************

I really wish some of you "programmers" out there would remember that programming is an art and a learning experience. The last thing someone who is frustrated and trying to learn something new needs is some sanctimonious, know-it-all lecturing them on how much they don't know. Why don't you try being a mentor instead or at least have the decency to not post anything at all if you don't intend to help. :rolleyes:

And people have the nuts to wonder why the world at large seems to be going to heck in a hand basket...look at how we treat each other when it comes to the simple things.

FreeriderUK - I assume that by now you have gotten a satisfactory answer from someone but for the benefit of others still searching....I hope this is of some help. :)
 
Last edited:
FreeriderUK said:
I'm doing it (Fill) because the dataset also includes calculated fields based on dates. When these dates are changed, the order the data is presented in needs to be refreshed too.
Which basically means using the previous cell address is pointless, that would also likely be the case if a new record was added by others between fills.
FreeriderUK said:
I tried the suggestion and the code in my previous post works.
OP found solution using BindingSource.Position and index of an id field.

supreme_good said:
programming is an art and a learning experience
Using a forum one can benefit from knowledge of more experienced people, people that may know better ways.

Giving advice even it goes agaist OPs current route is usually done with best of intensions. I'm sure exactly what you choked on in this thread, was it the suggestion of using a better database than Access? Or the qualified question why a Fill was done? Heck if I know, but I know that your two posts at these forums so far has only witnessed lack of knowledge and negativity. Perhaps you should take new angle from now on?
 
All that and you didn't even give the man the answer?!?

So if I asked you how to divide by zero, and we entered into a lengthy debate over whether or not it was a dumb request or impossible, or illogical and at the end it was just left.. you'd accept me coming back lambasting you for not providing an answer? Don't be so short-sighted.

I swear this is why I hate forums sometimes...
If you can't take the heat... Don't voice your opinion on the internet. Incase you never really understood what a forum is for, it's for discussion. It's not a Question and Answer session and people are free to give their free advice and their free opinions. Don't forget; everyone is entitled to my opinions ;)

they come out of the wood work to tell ya how wrong you are but NO ONE has an answer either! Unbelievable! :mad:
Er. There are some questions that have no answer, not because noone knows, but because those who would know the answer know that there is no answer.

Here is one way to get your record pointer back to it's original position after a refill of a dataset/datatable.
Yes, but it's not guaranteed to work, because youre foolishly expecting that your second fill operation will fill the exact same number of rows in the exact same order as the first fill operation. Maybe you'll be so blinded by rage at my telling you that you're wrong, that you will fail to see how dumb and illogical your solution is. Plain up, it's wrong, broken and thanks for trying but youre trying to solve a nonsensical question.

I really wish some of you "programmers" out there would remember that programming is an art
No, it's a science. When I look at an artist programmers work, it's the biggest pile of tosh I've ever seen.

The last thing someone who is frustrated and trying to learn something new needs is some sanctimonious, know-it-all lecturing them on how much they don't know.
I disagree. I'd assert that the last thing someone who is frustrated and in the dark needs guiding on how something should be done, not having all the answers of how to progress their broken solution. You don't seem to ahve grasped that people get it wrong all the time. What they get wrong is THEIR SOLUTION to the problem: There's a problem, they imagine a solution, it doesnt work, they come here asking how to make their broken solution work. Not the right way!
The right way is to teach of how to envisage a WORKABLE solution, and help them make that work. This is called..

Why don't you try being a mentor
..mentoring.

A mentor will not stand by and watch his mentee repeatedly doing something wrong because his appraoch is flawed. He guides and corrects the approach. That is what the discussion is about here.

or at least have the decency to not post anything at all
Actually, I wish people like you would have the decency not to post anything at all if all youre going to do is get the questioner further into a crappy unworkable solution, and disappear and leave us to tell him "sorry, but what you wrote was a crock and you need to rip it out and rewrite it"
People hate doing that, but all too often we see the story: "Someone on another forum told me to follow [insert name of 10 year old tutorial on SQL here] and I can't get it to work. Please help"

if you don't intend to help. :rolleyes:
Roll your eyes all you want, but in 10 years or so you'll come to know your stuff and you might well look back on this and realise exactly how much you DIDN'T help,

If youre struggling to understand it, suppose someone you know is going to jump off a building because they see that as the only solution. They are having trouble climbing the railing around the roof; the hit a problem with their solution. Do you solve their solution by saying "Actually, there are some step-ladders over there that you can use to get over the railings so you can jump"

It's an extreme analogy, but it's relevant! You did nothing to mentor and guide that person. You just helped them to overcome the hurdle with their broken solution.

And people have the nuts to wonder why the world at large seems to be going to heck in a hand basket...look at how we treat each other when it comes to the simple things.
I'm short of money. I have no job, no education, no family, no home, I'm an alcoholic and a broken man living on the streets. Will you give me money? It's the root cause of my biggest distress. I have no money to buy alcohol. Will you give me money?

Rarely is it the case that giving people what they want or need is the solution. Think on it.
 
Back
Top