开发者

selection issue in listview or TreeView

Hello i have a list view control,

While the form is being loaded i fill the list, i have aprrox. say 100+ items. While 开发者_StackOverflowfilling i check some parameters and decide which item/row need to be selected. i set the Selected property to true... refer the code below:

some lines here .....

ListViewItem listViewItem = new ListViewItem("COL1");
listViewItem.SubItems.Add("COL2");

check for some condition and then

listViewItem.Selected = true;
this.m_lstViewCtrl.Items.Add(listViewItem);

This does select the item, there are no issues with it... however, say the ctrl is sized to see onlu say some 15 items, but the selection is say some 35th item.... currently the scroll bar appears the item is selected but i have to scroll to see what was selected?

is it possible to scroll to the selected item so that is selection is clearly visible...

Will the same apply for a Treeview?


Use the EnsureVisible property on the ListViewItem.

UPDATE: So, your code would be as follows:

listViewItem.Selected = true;
listViewItem.EnsureVisible();
this.m_lstViewCtrl.Items.Add(listViewItem);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜