This is a migrated thread and some comments may be shown as answers.

Update vertical scroller position

1 Answer 292 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Michele
Top achievements
Rank 2
Michele asked on 21 Mar 2014, 04:00 PM
Hello,
     i'm using a RadListView in DetailsView mode.

When i insert an element in the Items collection of the RadListView, the Vertical-scrollbar's thumb remains snapped on the bottom to ensure the visibility of the last item. Items are inserted at the speed of almost one item per seconds.

I would like to control this behaviour, because (as all of the most common software do) i would like to stop refreshing the scrollbar position when the user click on the scrollbar or scrolls the wheel up to check more accurately an item.

Actually i'm doing this:

item insert:
private void ListView1AddLogMessage(string message, DateTime? dateTime)
  {
      if (dateTime == null)
          dateTime = DateTime.Now;
 
      if (userClicked)
          this.radListView1.BeginUpdate();
 
      LogList.Add(new LogItem { Info = message, Timestamp = dateTime.Value });
 
      if (userClicked)
          this.radListView1.EndUpdate();
  }


The userClicked variable is a bool that it's initialized like
bool userClicked = false;


and when I configure the ListView i bind the click and scroll events to simple functions that turns userClicked to be true, so that no update is performed.
void ThumbElement_Click(object sender, EventArgs e)
{
    userClicked = true;
}

But there are two main problems.
1) I would like to create an event similar to this one, for example if the user scroll wherever on the radlistview, probably he wants to stop the autorefresh, as it would probably be if he clicks on an element.
2) i would like to restore programmatically the auto refresh(plus the scrollbar-thumb autosnap to the bottom) when the users drag the thumb to the bottom of the scrollbar track


This seems to be a common behaviour to me for other application but i can't implement it in this case.

Thanks

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 26 Mar 2014, 11:49 AM
Hello Paolo,

Thank you for contacting Telerik Support.

If I understand your requirement correctly, you are trying to prevent the automatic selection of the newly added item to the RadListView, which leads the vertical scrollbar to the bottom. For this purpose you can use the CurrentItemChanging event as follows:
BindingList<LogItem> LogList = new BindingList<LogItem>();
 
public Form1()
{
    InitializeComponent();
    this.radListView1.ViewType = Telerik.WinControls.UI.ListViewType.DetailsView;
 
    for (int i = 0; i < 10; i++)
    {
        LogList.Add(new LogItem("Custom Message" + DateTime.Now.ToShortDateString(),DateTime.Now));
    }
 
    this.radListView1.DataSource = LogList;
    this.radListView1.CurrentItemChanging += radListView1_CurrentItemChanging;
    DetailListViewElement view = this.radListView1.ListViewElement.ViewElement as DetailListViewElement;
}
 
private void radListView1_CurrentItemChanging(object sender, ListViewItemChangingEventArgs e)
{
    e.Cancel = keepScrollbar;
}
 
private void Items_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
    keepScrollbar = false;         
}
 
bool userClicked = false;
bool keepScrollbar = false;
 
private void ListView1AddLogMessage(string message, DateTime? dateTime)
{
    keepScrollbar = true;
    if (dateTime == null)
        dateTime = DateTime.Now;
 
    if (userClicked)
        this.radListView1.BeginUpdate();
 
    LogList.Add(new LogItem { Info = message, Timestamp = dateTime.Value });
 
    if (userClicked)
        this.radListView1.EndUpdate();
}
 
public class LogItem
{
    public string Info { get; set; }
 
    public DateTime Timestamp { get; set; }
 
    public LogItem()
    {
    }
 
    public LogItem(string message, DateTime date)
    {
        this.Info = message;
        this.Timestamp = date;
    }
}
 
private void radListView1_Click(object sender, EventArgs e)
{
    ListView1AddLogMessage("Custom Message" + DateTime.Now.ToShortDateString(), DateTime.Now);
}

Note that adding new items leads to recalculating the scrollbar's size according to the current number of items. The scrollbar's value is kept the same, but it may be noticed a slight resizing of the scrollbar, which is normal.

If it is not the exact requirement, please specify more details about the specific case. Thus, we would be able to investigate the precise case and suggest a suitable solution. Thank you in advance.

I hope this information helps. Should you have further questions, I would be glad to help.
 
Regards,
Desislava
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
Tags
ListView
Asked by
Michele
Top achievements
Rank 2
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or