Most Recently Used for objects on a form
02-Feb-1010 Leave a comment
Probably other ways of doing this. However this is my quickly devised method. Using a MRUToolStripDropDownButton.
Need to call MRUAdd after loading an object
Private mruList As IList(Of T)
Private Sub MRUAdd()
If mruList.Contains(Me.cPadMain) Then
mruList.Remove(Me.cPadMain)
End If
'Lambda
If mruList.Where(Function(m) m.ID = cPadMain.ID).Count = 0 Then
mruList.Insert(0, Me.cPadMain)
End If
MRUDisplay()
End Sub
Private Sub MRUDisplay()
MRUToolStripDropDownButton.DropDownItems.Clear()
'LINQ
Dim MRU As IEnumerable(Of PadMain) = From pm In mruList Order By pm.PadMaterial Descending
For Each pm As PadMain In MRU
Dim tsi As New ToolStripMenuItem
tsi.Tag = pm.ID
tsi.Text = pm.Pad + " in " + pm.Material.Material + " " + pm.ID.ToString
MRUToolStripDropDownButton.DropDownItems.Insert(0, tsi)
If MRUToolStripDropDownButton.DropDownItems.Count > 10 Then
Exit For
End If
Next
End Sub