したがって、データベースからのデータがデータグリッドビューに入力されています。この時点で、ユーザーはデータグリッドビュー内の1つ以上の行を(マウスクリック/キーを押して)選択する場合と選択しない場合があります。
(選択時に)新しいデータセット、データテーブルを作成し、前述のdatagridviewからのいくつかのデータを含む行を追加する必要があります。
たとえば、テーブルに名前しかなかった場合、たとえば
Joe
Sean
Larry
Chris
ユーザーがクリックしたら、SeanとLarryの上で選択範囲をドラッグして、これらの名前を新しいデータセットに追加し、さらに処理するために別のメソッドに渡すことができるようにします。
これが私がいるところです。
'Get index of current row
Dim currentMouseRow As New Integer
currentMouseRow = dataGridView_UnAssodevices.HitTest(e.X, e.Y).RowIndex
'grab cell data of selected rows
Dim ds As New DataSet
Dim dt As New DataTable
For Each row As DataGridViewRow In dataGridView_UnAssodevices.SelectedRows
Dim dr As New DataGridViewRow
Dim data As New DataGridViewTextBoxCell
data.Value = row.Cells(0).Value
dr.Cells.Add(data)
dt.Rows.Add(dr)
MessageBox.Show(data.ToString)
Next
'Add contextmenu if right clicked
If e.Button = MouseButtons.Right Then
Dim m As New ContextMenu()
If currentMouseRow >= 0 Then
dataGridView_UnAssodevices.Rows(currentMouseRow).Selected = True
m.MenuItems.Add(New MenuItem("View Full Device Info"))
m.MenuItems.Add(New MenuItem("Associate Device(s)"))
End If
m.Show(dataGridView_UnAssodevices, New Point(e.X, e.Y))
End If
しかし、私はこのエラーを受け取り続けます:
Input array is longer than the number of columns in this table.
列宣言が欠落しているか、テーブルをセットに追加していないようです。