0

Starting Point: I have a datagridview with a combobox. The combobox has about 30 options (growing) and every user uses the options with a different frequency.

Question: I am looking for a way to sort the options in that combobox by usage for every client.

What I tried: I tried to use a counter and store that value in an external .txt file and open that again when the user opens his client again. Is there another way since this is a bad solution.

Additional Information: I update the clients with ClickOnce.

4

1 回答 1

0

如果您将添加到组合框的每个项目都设为包含计数属性的自定义类,则重写 ToString 方法将允许将对象直接添加到组合框。使用列表来跟踪排序与 combobox.items 集合的 AddRange 方法配合得很好。

Public Class CBItem
    Public Item As String = ""
    Public Count As Integer = 0
    Public Overrides Function ToString() As String
        Return Item
    End Function
End Class

    Dim CBItems As New List(Of CBItem)
    'This adds items to the list for demonstration purposes
    For i = 1 To 5
        CBItems.Add(New CBItem With {.Item = i.ToString, .Count = 5 - i})
    Next
    CBItems = CBItems.OrderBy(Function(x) x.Count).ToList
    ComboBox1.Items.AddRange(CBItems.ToArray)

My.Settings对于在使用之间存储列表可能很方便。

于 2013-11-06T18:58:34.360 回答