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(nI ndex, LVIS_SELECTED, LVIS_SELECTED);
m_database.EnsureVisible(n Index, 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.
int nIndex = nIndex = m_database.GetTopIndex();
m_database.SetFocus();
m_database.SetItemState(nI
m_database.EnsureVisible(n
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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(n