خرید بک لینک

Vote count: 0

i'm trying to delete rows in a datagridview that will be dynamically created, i used this code but it's not working (dgv is not a member of...)

the datagridviews are created as follow:

If ComboBox1.Text = "Excel" Then
        Static Dim cmd As String
        Using fold As New OpenFileDialog
            fold.Filter = "sheet files (*.xls)|*.xls|All files (*.*)|*.*"
            fold.Title = "Select file"
            If fold.ShowDialog() = Windows.Forms.DialogResult.OK Then
                fold.RestoreDirectory = True
                cmd = fold.FileName
            End If
        End Using
        Try
            Static Dim MyCoection As System.Data.OleDb.OleDbCoection
            Dim Dataset As System.Data.DataSet
            Static Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
            Dim shlist As ArrayList = getExcelSheetsName(cmd)
            MyCoection = New System.Data.OleDb.OleDbCoection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & cmd & ";Extended Properties=Excel 8.0;")
            For i As Long = 0 To shlist.Count() - 1
                Dim myTabPage As New TabPage()
                Dim dgv As DataGridView = New DataGridView()
                myTabPage.Text = shlist(i) & (TabControl1.TabPages.Count + 1)
                TabControl1.TabPages.Add(myTabPage)
                myTabPage.Controls.Add(dgv)
                dgv.Dock = DockStyle.Fill
                dgv.AutoSizeColumnsModeDataGridViewAutoSizeColumnsMode.Fill
                MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [" & shlist(i) & "$]", MyCoection)
                Dataset = New System.Data.DataSet
                MyCommand.Fill(Dataset)
                dgv.DataSource = Dataset.Tables(0)
                MyCoection.Close()
            Next

        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try

    End If

and the code of the delete button is :

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    For Each row As DataGridViewRow In TabControl1.SelectedTab.datagridview.SelectedRows
        DataGridView.Rows.Remove(row)
    Next
End Sub

Any help will be appreciated... Thank You

asked 3 mins ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 3 فروردين 1395 ساعت: 6:11

صفحه بندی