Hi
( First of all I need to clarify that I could manage both C# or VB solution to solve this issue )
I have a RadListControl where I would like to use it to list the runing processes in the system (with a condition that no more than 1 process with the same name),
that thing is done and I'm trying to update the list each 2 seconds (firstly determining If exists changes to update the current list),
I'm saving the SelectedItems property of the control to restore the selected items in the RadListControl after updating the list and here is the problem, after clearing the items of the control using the Items.Clear method the Scrollbar moves up to the top of the control and I need to scrolldown to the desired position again and again.
I would like to keep the current position after updating the items in the control, just like Windows TaskManager does for example.
I also tried to set a collection of RadDataItem as the control DataSource, but then the Image property for each item is empty (I don't know why).
I attached a gif in this post that demonstrates the problem,
As you can see in the Gif, when I run a new process (the window which is at the left border of the gif) the process list is moved to top, and the same thing happens when I close that process.
I don't know what more to try, here is the relevant part of the code:
Thanks in advance.
PS:
What I did time ago to solve this issue with a normal ListBox control is this (I can't reproduce it in a RadListControl):
( First of all I need to clarify that I could manage both C# or VB solution to solve this issue )
I have a RadListControl where I would like to use it to list the runing processes in the system (with a condition that no more than 1 process with the same name),
that thing is done and I'm trying to update the list each 2 seconds (firstly determining If exists changes to update the current list),
I'm saving the SelectedItems property of the control to restore the selected items in the RadListControl after updating the list and here is the problem, after clearing the items of the control using the Items.Clear method the Scrollbar moves up to the top of the control and I need to scrolldown to the desired position again and again.
I would like to keep the current position after updating the items in the control, just like Windows TaskManager does for example.
I also tried to set a collection of RadDataItem as the control DataSource, but then the Image property for each item is empty (I don't know why).
I attached a gif in this post that demonstrates the problem,
As you can see in the Gif, when I run a new process (the window which is at the left border of the gif) the process list is moved to top, and the same thing happens when I close that process.
I don't know what more to try, here is the relevant part of the code:
Private
Sub
Timer_RefreshProcessList_Tick(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs) _
Handles
Timer_RefreshProcessList.Tick
' Processes that shouldn't be listed.
Dim
BlackListedProcesses
As
String
() =
{
My.Application.Info.AssemblyName,
"Idle"
,
"System"
,
"audiodg"
}
' Get the runing processes.
Dim
Processes
As
Process() = Process.GetProcesses
' Filter the processes by its name
' then set the RadListDataItem items containing the names and the process icons.
Dim
ProcessItems
As
IEnumerable(Of RadListDataItem) =
(From proc
As
Process
In
Processes
Where
Not
BlackListedProcesses.Contains(proc.ProcessName)
Order By proc.ProcessName Ascending).
GroupBy(
Function
(proc
As
Process) proc.ProcessName).
Select
(
Function
(procs
As
IGrouping(Of
String
, Process))
If
Not
procs.First.HasExited
Then
Try
Return
New
RadListDataItem
With
{
.Active =
False
,
.Text =
String
.Format(
"{0}.exe"
, procs.First.ProcessName),
.Image = ResizeImage(Icon.ExtractAssociatedIcon(procs.First.MainModule.FileName).ToBitmap,
Width:=16, Height:=16)
}
Catch
ex
As
Exception
Return
Nothing
End
Try
Else
Return
Nothing
End
If
End
Function
)
' If the RadListControl does not contain any item then...
If
Me
.RadListControl_ProcessList.Items.Count = 0
Then
With
Me
.RadListControl_ProcessList
.BeginUpdate()
.Items.AddRange(ProcessItems)
' Add the RadListDataItems for first time.
.EndUpdate()
End
With
Exit
Sub
End
If
' If RadListDataItems count is not equal than the runing process list count then...
If
Me
.RadListControl_ProcessList.Items.Count <> ProcessItems.Count
Then
' Save the current selected items.
Dim
SelectedItems
As
IEnumerable(Of
String
) =
From Item
As
RadListDataItem
In
Me
.RadListControl_ProcessList.SelectedItems
Select
Item.Text
' For Each ctrl As RadListDataItem In ProcessItems
' ctrl.Dispose()
' Next
With
Me
.RadListControl_ProcessList
' .AutoScroll = False
' .SuspendSelectionEvents = True
' .SuspendItemsChangeEvents = True
' .SuspendLayout()
' .BeginUpdate()
.Items.Clear()
' Clear the current RadListDataItems
.Items.AddRange(ProcessItems)
' Add the new RadListDataItems.
' .EndUpdate()
' .ResumeLayout()
End
With
' Restore the selected item(s).
For
Each
Item
As
RadListDataItem
In
Me
.RadListControl_ProcessList.Items
If
SelectedItems.Contains(Item.Text)
Then
Item.Selected =
True
Item.Active =
True
With
Me
.RadListControl_ProcessList
' .ScrollToItem(Item)
' .ListElement.ScrollToItem(Item)
' .ListElement.ScrollToActiveItem()
End
With
End
If
Next
Item
With
Me
.RadListControl_ProcessList
' .AutoScroll = True
' .SuspendSelectionEvents = False
' .SuspendItemsChangeEvents = False
End
With
End
If
End
Sub
Thanks in advance.
PS:
What I did time ago to solve this issue with a normal ListBox control is this (I can't reproduce it in a RadListControl):
' [ListBox] Select item without jump
'
' Original author of code is "King King"
' Url: stackoverflow.com/questions/19479774/how-to-prevent-listbox-jumps-to-item
'
' Examples :
'
' Select_Item_Without_Jump(ListBox1, 50, ListBoxItemSelected.Select)
'
' For x As Integer = 0 To ListBox1.Items.Count - 1
' Select_Item_Without_Jump(ListBox1, x, ListBoxItemSelected.Select)
' Next
''' <summary>
''' Indicates whether the ListBox Item should be Selected or Unselected.
''' </summary>
Private
Enum
ListBoxItemSelected
''' <summary>
''' Indicate that ListBox Item should be Selected.
''' </summary>
[
Select
] = 1
''' <summary>
''' Indicate that ListBox Item should be Unselected.
''' </summary>
[Unselect] = 0
End
Enum
''' <summary>
''' Selects or unselects a ListBox Item without jumping to the Item location on the layout.
''' </summary>
Public
Shared
Sub
Select_Item_Without_Jump(lb
As
ListBox, index
As
Integer
, selected
As
ListBoxItemSelected)
Dim
i
As
Integer
= lb.TopIndex
' Store the selected item index
lb.BeginUpdate()
' Disable drawing on control
lb.SetSelected(index, selected)
' Select the item
lb.TopIndex = i
' Jump to the previous selected item
lb.EndUpdate()
' Eenable drawing
End
Sub