Most Recently Used for objects on a form

 
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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: