BryanZM Posted August 7, 2003 Posted August 7, 2003 Just a tip, I was perusing through dotnetforums looking for a way to scroll to the bottom of a list view automatically. I found this code to subclass the listview control to scroll to bottom: ------------------------------------------------------------------------ public class ScrollerListView : ListView { // values obtained from winusr.h const int WM_SCROLL = 0x0115; const IntPtr SB_BOTTOM = (IntPtr) 7; public void AddItem( ListViewItem new_item ) { // add the item to the items collection Items.Add( new_item ); // have to Create a message Message msg = Message.Create( Handle, // the hwnd handle WM_VSCROLL, // uMsg SB_BOTTOM, // wParam IntPtr.Zero ); // null as not sent by scrollbar // call protected WndProc method WndProc( ref msg ); } } ------------------------------------------------------------------------- However i found a way that may be better without subclassing. The listview control has a way built in to scroll to bottom. Here is a sample: ------------------------------------------------------------------------- private FillListView(dt) { foreach(DataRow dr in dt) { //fill list view.... ............. ............ } int intCnt = 0 ; intCnt = listView1.Items.Count -1 ; // ensure that item count is greater than zero... if(intCnt > 0) { // Getting item count and using it with the EnsureVisible // method enures that the listview will always scroll to // bottom. listView1.Items[intCnt].EnsureVisible() ; } } ---------------------------------------------------------------------- I hope will help somebody out there. BryanZM Quote
*Experts* Volte Posted August 7, 2003 *Experts* Posted August 7, 2003 ListBox1.TopIndex = ListBox1.Items.Count - 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.