[Visual Studio 2005 Express Edition CD(DVD)イメージ版]
http://download.microsoft.com/download/A/B/4/AB4DA3D7-CC3A-4081-9FC8-E35653E85499/vb.iso

[Visual Studio 2005 Express Edition WEBインストール版]
http://go.microsoft.com/fwlink/?LinkId=51405&clcid=0x411

[仮想CD-ROMドライブ:Virtual CD-ROM Control Panel]
https://www.microsoft.com/en-us/download/details.aspx?id=38780
https://www.microsoft.com/en-us/download/confirmation.aspx?id=38780


SQLで任意の項目順でソートする方法(ORDER BY FIELD(フィールド名, 値3, 値9, 値5, ・・・))

/* 例 */
SELECT
  MemberID
FROM
  TARGET_TABLE
WHERE
  MemberID IN ('id11111', 'id99999', 'id55555', 'id33333', 'id77777')
ORDER BY
  FIELD(MemberID, 'id11111', 'id99999', 'id55555'), 
  FIELD(MemberID, 'id33333', 'id77777');
ORDER BY FIELDに指定した順番でソートされる。

ListViewで選択変更時の動作制御サンプル

    '----------------------------------------
    '現在の選択行番号(新規モードになったら"-1"にするのを忘れるな!!)
    '----------------------------------------
    Private CurrentItemIndex As Integer = -1

    '----------------------------------------
    ' キーボードでの行選択変更
    '----------------------------------------
    Private Sub lstView_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles lstView.KeyUp
        Try
            '行が選択されていないときは無視
            If lstView.SelectedItems.Count = 0 Then
                Exit Sub
            End If

            '選択後の行番号を退避
            Dim SelectedItemIndex As Integer = Me.lstView.SelectedItems(0).Index

            '同じ行を選択したときは無視
            If CurrentItemIndex = SelectedItemIndex Then
                Exit Sub
            End If

            '入力データ退避
            Dim wkItem1 As String = Me.txtItem1.Text
            Dim wkItem2 As String = Me.txtItem2.Text
            Dim wkItem3 As String = Me.txtItem3.Text

            Dim isDataChanged As Boolean = False    'データ変更フラグ
            Dim flgRowChange As Boolean = True      '行変更許可フラグ

            If CurrentItemIndex <> -1 Then
                '選択前のデータが変更されていた場合
                If (Me.lstView.Items(CurrentItemIndex).SubItems(列項目.項目1).Text <> wkItem1) OrElse _
                   (Me.lstView.Items(CurrentItemIndex).SubItems(列項目.項目2).Text <> wkItem2) OrElse _
                   (Me.lstView.Items(CurrentItemIndex).SubItems(列項目.項目3).Text <> wkItem3) Then
                    isDataChanged = True
                End If

                'データが変更されている場合に行選択変更の確認メッセージを表示
                If isDataChanged = True Then
                    If MessageBox.Show("データが変更されています。" & vbCrLf & "選択を変更してもよろしいですか?", _
                                       "確認", MessageBoxButtons.OKCancel, _
                                       MessageBoxIcon.Question, _
                                       MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Cancel Then
                            Me.lstView.Items(CurrentItemIndex).Selected = True    '選択行変更
                            Me.lstView.Items(CurrentItemIndex).Focused = True     '選択行にフォーカスをセット
                            flgRowChange = False    '選択前の行に戻す
                    End If
                                       
                End If
            End If

            Select Case flgRowChange
                Case True
                    '選択した行のデータを表示
                    Me.txtItem1.Text = Me.lstView.SelectedItems(0).SubItems(列項目.項目1).Text
                    Me.txtItem2.Text = Me.lstView.SelectedItems(0).SubItems(列項目.項目2).Text
                    Me.txtItem3.Text = Me.lstView.SelectedItems(0).SubItems(列項目.項目3).Text

                    '選択後の行番号を退避
                    CurrentItemIndex = SelectedItemIndex

                Case False
                    '選択前の行のデータを表示
                    Me.txtItem1.Text = wkItem1
                    Me.txtItem2.Text = wkItem2
                    Me.txtItem3.Text = wkItem3

           End Select

            _mode = モード.変更

            Call SetModeLabel(_mode)

        Catch ex As Exception
            MessageBox.Show(ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try
    End Sub

    '----------------------------------------
    ' マウスでの行選択変更
    '----------------------------------------
    Private Sub lstView_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles lstView.MouseUp
        Try
            '行が選択されていないときは無視
            If lstView.SelectedItems.Count = 0 Then
                Exit Sub
            End If

            '選択後の行番号を退避
            Dim SelectedItemIndex As Integer = Me.lstView.SelectedItems(0).Index

            '同じ行を選択したときは無視
            If CurrentItemIndex = SelectedItemIndex Then
                Exit Sub
            End If

            '入力データ退避
            Dim wkItem1 As String = Me.txtItem1.Text
            Dim wkItem2 As String = Me.txtItem2.Text
            Dim wkItem3 As String = Me.txtItem3.Text

            Dim isDataChanged As Boolean = False    'データ変更フラグ
            Dim flgRowChange As Boolean = True      '行変更許可フラグ

            If CurrentItemIndex <> -1 Then
                '選択前のデータが変更されていた場合
                If (Me.lstView.Items(CurrentItemIndex).SubItems(列項目.項目1).Text <> wkItem1) OrElse _
                   (Me.lstView.Items(CurrentItemIndex).SubItems(列項目.項目2).Text <> wkItem2) OrElse _
                   (Me.lstView.Items(CurrentItemIndex).SubItems(列項目.項目3).Text <> wkItem3) Then
                    isDataChanged = True
                End If

                'データが変更されている場合に行選択変更の確認メッセージを表示
                If isDataChanged = True Then
                    If MessageBox.Show("データが変更されています。" & vbCrLf & "選択を変更してもよろしいですか?", _
                                       "確認", MessageBoxButtons.OKCancel, _
                                       MessageBoxIcon.Question, _
                                       MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Cancel Then
                            Me.lstView.Items(CurrentItemIndex).Selected = True    '選択行変更
                            Me.lstView.Items(CurrentItemIndex).Focused = True     '選択行にフォーカスをセット
                            flgRowChange = False    '選択前の行に戻す
                    End If
                                       
                End If
            End If

            Select Case flgRowChange
                Case True
                    '選択した行のデータを表示
                    Me.txtItem1.Text = Me.lstView.SelectedItems(0).SubItems(列項目.項目1).Text
                    Me.txtItem2.Text = Me.lstView.SelectedItems(0).SubItems(列項目.項目2).Text
                    Me.txtItem3.Text = Me.lstView.SelectedItems(0).SubItems(列項目.項目3).Text

                    '選択後の行番号を退避
                    CurrentItemIndex = SelectedItemIndex

                Case False
                    '選択前の行のデータを表示
                    Me.txtItem1.Text = wkItem1
                    Me.txtItem2.Text = wkItem2
                    Me.txtItem3.Text = wkItem3

           End Select

            _mode = モード.変更

            Call SetModeLabel(_mode)

        Catch ex As Exception
            MessageBox.Show(ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try
    End Sub

プログレスダイアログサンプル

Public Class MainForm

    Private Enum カラム
        ID
        ファイル名
        座席数
    End Enum

    Private Sub btnOK_Click( sender As Object,  e As EventArgs) Handles btnOK.Click
        Try
            Dim mode As Integer = 0
            Integer.TryParse(InputBox("0か1", "0"), mode)
            Using dlg As New ProgressDialog(Me, Me.lstList, mode)
                dlg.ShowDialog(Me)
            End Using

        Catch ex As Exception
            MessageBox.Show(ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
End Class

'----------------------------------------------------------------------------------------------------
Public Class ProgressDialog

    Public WithEvents bgWorker As New System.ComponentModel.BackgroundWorker

    Private frmOwner As System.Windows.Forms.Form = Nothing
    Private lstList As System.Windows.Forms.ListView = Nothing
    Private _mode As Integer = 0

    Public Event Terminated(ByVal sender As Object, ByVal e As System.EventArgs)

    Private Delegate Sub DialogVisibleDelegate(ByVal flg As Boolean)
    Private Delegate Sub ShowMessageBoxDelegate(ByVal OwnerForm As System.Windows.Forms.Form)
    Private Delegate Sub SetListItemDelegate()

    Public Sub New(ByVal OwnerForm As System.Windows.Forms.Form, ByVal lst As System.Windows.Forms.ListView, ByVal mode As Integer)
        
        ' この呼び出しはデザイナーで必要です。
        InitializeComponent()
        
        ' InitializeComponent() 呼び出しの後で初期化を追加します。
        frmOwner = OwnerForm
        lstList = lst
        _mode = mode
    End Sub

    Private Sub ProgressDialog_Load(sender As Object, e As EventArgs) Handles Me.Load
        bgWorker.RunWorkerAsync()

        AddHandler Terminated, AddressOf DialogClose
    End Sub

    Private Sub bgWorker_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgWorker.DoWork
        Select Case _mode
            Case 0 : Call Subrutine0()
            Case 1 : Call Subrutine1()
        End Select
        
    End Sub

    Private Sub bgWorker_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgWorker.RunWorkerCompleted
        RaiseEvent Terminated(Me, Nothing)
    End Sub

    Private Sub DialogClose(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub DialogVisible(ByVal flg As Boolean)
        Me.Visible = flg
    End Sub

    Private Sub ShowMessageBox(ByVal OwnerForm As System.Windows.Forms.Form)
        Me.Invoke(New DialogVisibleDelegate(AddressOf DialogVisible), New Object() {False})
        If MessageBox.Show(OwnerForm, "中断しますか?", "メッセージ", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.No Then
            If Me.InvokeRequired = True Then
                Me.Visible = True
            Else
                Me.Invoke(New DialogVisibleDelegate(AddressOf DialogVisible), New Object() {True})
            End If
        Else
            Me.Close()
        End If
    End Sub

    Private Sub SetListItem()
        Dim newItem() As String = New String() {"", "File4", "40"}
        Dim listItem As New ListViewItem(newItem)
        Me.lstList.Items.Add(listItem)
    End Sub

    Private Sub Subrutine0()
        For ix1 As Integer = 0 To Me.lstList.Items.Count - 1
            Threading.Thread.Sleep(1000)
            If ix1 = 1 Then
                Me.Invoke(New ShowMessageBoxDelegate(AddressOf ShowMessageBox), New Object() {frmOwner})
            End If
        Next ix1
    End Sub

    Private Sub Subrutine1()
        Threading.Thread.Sleep(1000)
        Me.Invoke(New SetListItemDelegate(AddressOf SetListItem))
        Threading.Thread.Sleep(1000)
    End Sub
End Class

DataTableのSelect例

    Private Enum 検索条件
        予約番号_前
        予約番号_後
        連番
        座席連番
        公演日
        開演時間
    End Enum

    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        Try
            Dim lstTextBox As New System.Collections.Generic.List(Of System.Windows.Forms.TextBox)
            With lstTextBox
                .Add(Me.txtReserveNo1)
                .Add(Me.txtReserveNo2)
                .Add(Me.txtSeatDispNo)
                .Add(Me.txtSeatSerialNo)
                .Add(Me.txtShowDate)
                .Add(Me.txtShowTime)
            End With

            Dim Filter As String = String.Empty

            For i As Integer = 0 To lstTextBox.Count - 1
                Dim temp As String = String.Empty
                If Not String.IsNullOrEmpty(lstTextBox(i).Text) Then
                    Select Case i 
                        Case 検索条件.予約番号_前
                            temp = "CONVERT(SUBSTRING(QRコード, 13, 4), 'System.Int32') = " & CType(lstTextBox(i).Text, Integer)

                        Case 検索条件.予約番号_後
                            temp = "CONVERT(SUBSTRING(QRコード, 17, 7), 'System.Int32') = " & CType(lstTextBox(i).Text, Integer)

                        Case 検索条件.連番
                            temp = "CONVERT(SUBSTRING(QRコード, 24, 5), 'System.Int32') = " & CType(lstTextBox(i).Text, Integer)

                        Case 検索条件.座席連番
                            temp = "CONVERT(SUBSTRING(QRコード, 29, 7), 'System.Int32') = " & CType(lstTextBox(i).Text, Integer)

                        Case 検索条件.公演日
                            temp = "CONVERT(SUBSTRING(QRコード, 36, 8), 'System.Int32') = " & CType(lstTextBox(i).Text, Integer)

                        Case 検索条件.開演時間
                            temp = "CONVERT(SUBSTRING(QRコード, 44, 4), 'System.Int32') = " & CType(lstTextBox(i).Text, Integer)

                        Case Else

                    End Select
                End If

                If Not String.IsNullOrEmpty(temp) AndAlso Filter.Length > 0 Then
                    Filter &= " AND "
                End If
                Filter &= temp
            Next i

            Dim view As DataView = New DataView(Me.QRLIST)
            With view
                .RowFilter = Filter
                .Sort = "QRコード ASC"
            End With

            Me.RESULT.Rows.Clear()
            For i As Integer = 0 To view.Count - 1
                Dim row As DataRow = Nothing
                row = Me.RESULT.NewRow
                row.Item("QRコード") = view(i).Item("QRコード")
                Me.RESULT.Rows.Add(row)
            Next i

            Me.dsResult.AcceptChanges()
            With Me.dgvResult
                .DataSource = Me.dsResult
                .DataMember = Me.RESULT.TableName
            End With

        Catch ex As Exception
            MessageBox.Show(ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

付箋紙ツール

付箋帳