refreshing a listctrl

ok here is what I have.  I am opening up fields from a database and displaying them inside of a listctrl.  Now when I select of the fields and make changes to that field, in the database, I want the changes to show up in the listctrl.  Now what I am doing to do that is just reopen the database to show the changes.  Now I want the field that I chose in the listctrl to be in view.  I can't seem to get that to work.  Here is the code that I am using.

int nIndex = nIndex = m_database.GetTopIndex();

                  m_database.SetItemState(nIndex, LVIS_SELECTED, LVIS_SELECTED);
                  m_database.EnsureVisible(nIndex, TRUE);

m_database is my Meber Variable for my listctrl.  Those functions are called when I press a button.  Now when it runs the first time it works but when I do it again it selects a field that is 3 fields above the one that I want selected.  Sometimes it doesn't even work the first time.  Is this a VC error or is it something that I am doing wrong.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BOOL EnsureVisible( int nItem, BOOL bPartialOK );

The list view control is scrolled if necessary. If the bPartialOK parameter is nonzero, no scrolling occurs if the item is partially visible.

so call it like this:
m_database.EnsureVisible(nIndex, 0);
Sounds like something wrong.

The problem appears to be that you are calling GetTopIndex() .. this is just going to give you the topmost line in the list.  The item you last worked with might be anywhere in the list.

EnsureVisible will not scroll the selected item to the top .. only scrolls enough to amke it visible, it could well be at the bottom (or in the middle) of the display.

Instead, find the selected item (easy call) and remember that between calls (stick it in a member variable).

PS: Seeing some of your code might help

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
simongodAuthor Commented:
thanks for the help but I figured out the question myself.  It was because I was using the GetTopIndex function.  I changed it to another that works better.  I will give you the points but you really didn't do a thing to help me.  sorry
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.