Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent! Unbound DataGrid

Status
Not open for further replies.

MickeD

Programmer
Feb 20, 2000
54
Hi all!

How can I add/modify/delete data in datagrid if it's not connected to any database?

This is a code:
Code:
        myDataSet = New DataSet("myDataSet")
        Dim tMap As DataTable
        tMap = New DataTable("Map")

        ' Create two columns

        Dim cSource As DataColumn
        cSource = New DataColumn("Source")
        Dim cDest As DataColumn
        cDest = New DataColumn("Dest")
        tMap.Columns.Add(cSource)
        tMap.Columns.Add(cDest)

        ' Add the tables to the DataSet.
        myDataSet.Tables.Add(tMap)
        
        grdMapping.SetDataBinding(myDataSet, "Map")
 

you need to create DataRow object. Follow the sample below

Dim objDS As New DataSet()

'Create data table.
Dim myDataTable As New DataTable("myTable")

'Create two columns.
Dim col1 As New DataColumn()
Dim col2 As New DataColumn()

'Add columns to the data table.
myDataTable.Columns.Add(col1)
myDataTable.Columns.Add(col2)

'Create data row.
Dim myDataRow As DataRow

'Assign values to the row.
myDataRow = myDataTable.NewRow
myDataRow(0) = "Pankaj"
myDataRow(1) = "Banga"

'Add data row to data table.
myDataTable.Rows.Add(myDataRow)

'Add data table to the DataSet.
objDS.Tables.Add(myDataTable)

'Bind DataSet to the DataGrid.
DataGrid1.SetDataBinding(objDS, "myTable")

 

you can even bind DataTable to DataGrid instead of using DataSet object.


'Bind DataTable to the DataGrid.
DataGrid1.DataSource = myDataTable


 
Hi PankajBanga,

I have this code in form_load event.
After then I want to add rows of data into grid.
What object can I use. I tryed
Code:
grdMapping.DataSource.Rows.Add(myDataRow)
but I got error
 

add DataRow object to DataTable.

something like this:

'Create DataRow.
Dim myDataRow As DataRow

'Assign value to DataRow.
myDataRow = myDataTable.NewRow
myDataRow(0) = "yourValue"

'Add DataRow to DataTable.
myDataTable.Rows.Add(myDataRow)


see the 6th post in the following thread, it might help you!!!

Thread796-597966

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top