微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Listbox: scroll to the selected item by code

I have code that selects - find and select - 1 item in a large listBox. This
works Ok but most of the time the selected item isn't visible without
scrolling down manualy. Is this possible by code?

------------------

I'm marking listBox items as selected, and I'd like to scroll listBox to
a selected entry if it is off-screen. How can I do it?

-------------------

You can use JavaScript to reset the scroll position though. When the page is submitted to the server store the scroll position in a HiddenField (make sure it's an ASP.NET HiddenField so that the ViewState can be remembered). That way when the request comes back you can use JavaScript to retrieve the scroll position and reset the scroll position.

----------------

(C#, Windows Form)
this.listView1.Select();
this.listView1.Items[ret].Selected = true;
this.listView1.EnsureVisible(ret);

----------------

ASP.NET, C#, Ajax (NOTE: server script does not work; client script work correctly.)

ScriptManager.RegisterStartupScript(this, this.GetType(), "EnsureSeletedItemVisible", "document.getElementById('"+this.lbUnassigned.ClientID+"').selectedindex="+this.lbUnassigned.Selectedindex.ToString(), true);

 

REF:

http://bytes.com/topic/c-sharp/answers/257674-listbox-scroll

http://bytes.com/topic/access/answers/191145-listbox-scroll-selected-item-code

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐