だから私は以下に示すようなクラスを持っています:
Public Class parameters
Public Property test As String
Public Property test_type As String
Public Property user_test_name As String
Public Property meas As String
Public Property spec_min As String
Public Property spec_max As String
Public Property spec_unit As String
Public Overrides Function ToString() As String
Return user_test_name
End Function
End Class
各オブジェクトをオブジェクトのリストに書き込み、それらをリストボックスに書き込みました。
リストボックス内のアイテムを上下に移動したいのですが、次のコードでうまくいきました:
Private Sub up_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles up.Click
'Move up
'Make sure our item is not the first one on the list.
If ListBox1.SelectedIndex > 0 Then
Dim I = ListBox1.SelectedIndex - 1
ListBox1.Items.Insert(I, ListBox1.SelectedItem)
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
ListBox1.SelectedIndex = I
End If
End Sub
Private Sub down_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles down.Click
'Move down
'Make sure our item is not the last one on the list.
If ListBox1.SelectedIndex < ListBox1.Items.Count - 1 Then
'Insert places items above the index you supply, since we want
'to move it down the list we have to do + 2
Dim I = ListBox1.SelectedIndex + 2
ListBox1.Items.Insert(I, ListBox1.SelectedItem)
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
ListBox1.SelectedIndex = I - 1
End If
End Sub
しかし、選択したアイテムが上下に移動するにつれて、リスト内の実際のインデックスも変更したいと思います。このようにして、ファイルをエクスポートするときに、ユーザーが選択した順序を維持できます。お知らせ下さい?