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