输入数组比列数长

时间:2014-05-16 14:15:59

标签: vb.net datagridview vb.net-2010

在datagridview的拖拽事件中,我收到了这个错误:

enter image description here

这是我的拖拽事件的整个代码:

    Private Sub DataGridView1_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragDrop

    Dim clientPoint As Point = DataGridView1.PointToClient(New Point(e.X, e.Y))
    Dim hit As DataGridView.HitTestInfo = DataGridView1.HitTest(clientPoint.X, clientPoint.Y)

    Dim dgvr As DataGridViewRow = DirectCast(e.Data.GetData(GetType(DataGridViewRow)), DataGridViewRow)
    Dim celldata As Object() = New Object(dgvr.Cells.Count) {}
    For col As Integer = 0 To dgvr.Cells.Count - 1
        celldata(col) = dgvr.Cells(col).Value
    Next


    Dim dt As New DataTable()
    dt = ds_data.Tables(0)
    Dim colCheckbox As DataColumn = dt.Columns.Add("Column1", GetType(Boolean))
    Dim row As DataRow = dt.NewRow()
    row.ItemArray = celldata
    dt.Rows.InsertAt(row, hit.RowIndex)

    dgvr.DataGridView.Rows.Remove(dgvr)
    Dim sqlCmd As SqlCommand
    sqlCmd = con.CreateCommand()
    sqlCmd.CommandText = "update megatom_data_commande set ordre='" & hit.RowIndex & "' where id='" & DataGridView1.Rows(hit.RowIndex).Cells("ID").Value.ToString & "'"

    Try

        sqlCmd.ExecuteNonQuery()
        DataGridView2.DataSource = ds_data2.Tables(0).DefaultView
        DataGridView1.DataSource = ds_data.Tables(0).DefaultView
        Dim CMD As New SqlCommand("PLANNIFIER")
        CMD.Parameters.Add("@CHAINE", SqlDbType.VarChar).Value = cboChaine.SelectedItem.ToString

        ExecuteCMD(CMD)

    Catch ex As SqlException
    End Try
End Sub

实际上我的数据表有15列,但我手动添加了一个复选框列来选择行,所以我觉得我有索引问题,但我不知道如何解决这个问题。

我的ds_data定义如下代码:

   requestPlanifie = "select megatom_data_commande.id as ID,numéro,observation,moule,commande,id_etat,programme,ordre,moule,glav,Qté_commandée_Totale," _
       & " Qté_coupée_cuir, Qté_coupée_synthétique, Qté_piquée, Qté_finie from megatom_data_commande" _
& " inner join dbo.MEGATOM_DATA_MOULE on megatom_data_moule.id=megatom_data_commande.id_moule " _
& " where id_chaine='" & cboChaine.Text & "' and ( id_etat='3' or id_etat='4') order by numéro asc,ordre asc"
        Dim dataAdapter As New SqlDataAdapter(requestPlanifie, con)
         Try

            dataAdapter.Fill(ds_data, "ds_data")
            dataAdapter2.Fill(ds_data2, "ds_data2")
        Catch ex As SqlException


        End Try
       DataGridView1.DataSource = ds_data.Tables(0).DefaultView

0 个答案:

没有答案