Link to home
Start Free TrialLog in
Avatar of simongod
simongod

asked on

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.SetFocus();
                  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.
Avatar of wyy_cq
wyy_cq

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);
ASKER CERTIFIED SOLUTION
Avatar of RONSLOW
RONSLOW

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of simongod

ASKER

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