?
Solved

DataGridview: re select previously selected row after datasource refreshed

Posted on 2007-08-07
7
Medium Priority
?
272 Views
Last Modified: 2011-10-03
G'day
What's your favourite procedure for this simple task?
0
Comment
Question by:PiedBird
  • 4
  • 3
7 Comments
 
LVL 39

Accepted Solution

by:
appari earned 2000 total points
ID: 19650573
i do like this

Dim curPosCurManager As CurrencyManager
Dim curPos As Integer

curPosCurManager = CType(grdiviewName.BindingContext(grdiviewName.DataSource), CurrencyManager)
curPos = curPosCurManager.Position

' refresh the datasource here


curPosCurManager = CType(grdiviewName.BindingContext(grdiviewName.DataSource), CurrencyManager)
curPosCurManager.Position = curPos
               
0
 

Author Comment

by:PiedBird
ID: 19650697
appari
thanks, Nearly works.
I select a record on my dgv and open form in dialog to edit data. If I don't make any changes your code runs fine after the dialog form closes but if I edit the dialog form there is a problem.

when I call:
Me.SaleDetailsTableAdapter.Update(Me.DsTransaction.SaleDetails)   'in dialog form

I get this error:
Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

I don't know anything about your Dim curPosCurManager As CurrencyManager. Guess I better do some reading.

0
 

Author Comment

by:PiedBird
ID: 19650767
appari:
bare with me.
I think your code is probably not the cause of update problem. I seem to have made something very like an intermittent fault.... which isn't possible.
I'll be back soon.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:PiedBird
ID: 19650888
I thought this would be easy! Appari I again suspect my database some how thinks your code wants to update the same record as my dialog form. I think it (the database) was disturbed also by my readonly datagridview too but we seem to have overcome that.

Can I perhaps tell the database to ignore any other edits pending (this is a single user database anyway) when I call the update method of the table adapter on the dialog form? What code would do this?

I'm sorry if I have gone completely off track. Am trying to understand with insufficient mental resources!
0
 
LVL 39

Expert Comment

by:appari
ID: 19650896
what happens if you comment out the code i have provided? does it update without any errors?
the code i posted wont update anything its just reading the current position from the bound datasource.
0
 
LVL 39

Expert Comment

by:appari
ID: 19650897
can you post the existing code
0
 

Author Comment

by:PiedBird
ID: 19650950
I just commented out your code and got the update method to fail without it. Believe me this was the approach I was taking already but the method doesn't fail every time. I've got to work out what it is that makes the database think there is two edits to consider while I only know of one. I'll give you points on this question and open another on the concurrency problem. Hope you can have a look. Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question