Onega

a lot of VC++ posts, a few C# posts, and some miscellaneous stuff

Monday, July 11, 2005

ensure a row in CListCtrl is in top half

//ensure the desired item is in upper part of the

list control

//if it is in lower part of the list control, scroll

the listctrl so that it becomes the first row

//exception: the item can not be the first row if

there are not enough rows bellow it

//e.g. if total number of rows is 100, then you can't

expect row 99/98... to be the first row.

pListControl->EnsureVisible(nItem,FALSE);

int top_index = pListControl->GetTopIndex();

int count_per_page = pListControl->GetCountPerPage(

);

CRect selected_item_rect;



pListControl->GetItemRect(nItem,&selected_item_rect,LVIR_BOUNDS);

int position_in_view = nItem - top_index;

if(position_in_view > count_per_page/2)

{

CSize sz;

sz.cx = 0;

sz.cy = selected_item_rect.Height()*

position_in_view;//you can also scroll it to the

middle of the listcontrol

pListControl->Scroll(sz);

}

0 Comments:

Post a Comment

<< Home