(我需要澄清的是,我可以管理的一兩個C#或VB的解決方案來解決這個問題)Telerik的,更新RadListControl項目問題
前段時間我問this other question如何選擇項目或範圍在ListBox
沒有讓控制跳到那個位置,這個問題現在是類似的,我只想執行與該問題相同的事情,但與telerik RadListControl
。
我有一個RadListControl
我想用它來列出系統中的運行進程(條件是不超過1個具有相同名稱的進程),那件事就完成了,我試圖更新該列表每2秒(首先確定是否存在更改以更新當前列表), 我正在保存控件的SelectedItems
屬性,以在更新列表後恢復RadListControl
中的選定項目,這是清除後的問題控件的項目使用Items.Clear
方法滾動條移動到控件的頂部,我需要一次又一次滾動到所需的位置。 我想在更新控件中的項目之後保持當前位置,就像Windows TaskManager所做的那樣。
我也嘗試設置收集od RadDataItem
作爲控制DataSource
,但是然後每個項目的Image
屬性是空的(我不知道爲什麼)。
這是問題的一個示範:
正如你所看到的,當我(在GIF左側的窗口)運行一個新的進程的進程列表被移動到頂部,當我關閉該過程時也是如此。
我不知道還有什麼嘗試,這裏是代碼的相關部分:
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
如果我沒理解好,我只列出了指向'RadControl.SelectedItems'名單,但只是,只有指向它的項目,所以一旦我清除Control.SelectedItem列表我的列表也開始爲空,因爲有任何項目指向,我說得對嗎?,我不明白的是爲什麼要這樣做,因爲它解決了這個問題,我沒有做同樣的事情,但使用Linq ?,對不起我的英語,謝謝你的回答! – ElektroStudios 2014-10-03 15:49:53
@ElektroStudios對不起。見編輯:) – 2014-10-03 16:31:26