i have trouble to save DataGridView1,i dont know how to declare it

Imports System.Data.DataTable
Public Class Form3
    Dim table As New DataTable("Table")
    Dim index As Integer
    Dim DataGridView1 As String

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        table.Columns.Add("Nom", Type.GetType("System.String"))
        table.Columns.Add("Prenom", Type.GetType("System.String"))
        table.Columns.Add("Date de naissance", Type.GetType("System.String"))
        table.Columns.Add("Domicile", Type.GetType("System.String"))
        table.Columns.Add("Numero de telephone", Type.GetType("System.String"))
        DataGridView1.DataSource = table
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        table.Rows.Add(TextBoxN.Text, TextBoxP.Text, TextBoxDdn.Text, TextBoxD.Text, TextBoxNdt.Text)
        DataGridView1.DataSource = table
    End Sub

    Private Sub btnsuivant_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsuivant.Click
        Form4.Show()
    End Sub

    Private Sub btneffacer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneffacer.Click
        DataGridView1.Rows.RemoveAt(index)
    End Sub

    Private Sub Btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
        'clear TextBoxes
        TextBoxN.Text = ""
        TextBoxP.Text = ""
        TextBoxDdn.Text = ""
        TextBoxD.Text = ""
        TextBoxNdt.Text = ""
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        'save TextBoxes
        Dim isave As New SaveFileDialog
        isave.Filter = "txt files (*.txt) |*.txt"
        isave.FilterIndex = 2
        isave.RestoreDirectory = False

        If isave.ShowDialog() = DialogResult.OK Then
            IO.File.WriteAllText(isave.FileName, DataGridView1)
        End If


    End Sub
End Class
Racine MackossostudentAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi Racine;
 
You have defined the DatagridView as a string as shown here
Dim DataGridView1 As String

Open in new window

where it should be defined as follows
Dim DataGridView1 As New DataGridView()

Open in new window

Correct that to see if that helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NorieData ProcessorCommented:
Is the datagridview on a form?

If it is then I don't think you need to declare it.
0
Fernando SotoRetiredCommented:
From the information given I have posted the solution that is causing the issue.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.