Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...