Data Grid (VB.NET CF)

D

David Webb

Hi,

Does anyone have a snippet of code to manipulate the grid
programatically? Depending on my data, I add 1 or a few data grids to
a form programatically. To test, I just want to add one row and 2
columns of data. Eventually, I want to read a string and put x rows
and x columns of data in, but to begin with, I'd just be happy to know
how to add columns and rows. I saw a post by Peter Foot but I went to
the link and it gave me an error.

Any sample vb.net CF code snippets would be greatly appreciated.

Regards,

David.
 
A

Andrej Radinger

Here is a sample from MS Press book .NET COmpact Framework Core Reference.
Hope this helps:

' Create a DataSet with two tables and populate it.
Private Sub MakeDataSet()
' Create a DataSet.
myDataSet = New DataSet("myDataSet")

' Create a DataTable.
Dim tCust As New DataTable("Customers")

' Create three columns, and add them to the table.
Dim cCustID As New DataColumn("CustID", GetType(Integer))
Dim cCustName As New DataColumn("CustName")
Dim cCurrent As New DataColumn("Current", GetType(Boolean))
tCust.Columns.Add(cCustID)
tCust.Columns.Add(cCustName)
tCust.Columns.Add(cCurrent)

' Add the table to the DataSet.
myDataSet.Tables.Add(tCust)

' Create three customers in the Customers Table.
Dim newRow1 As DataRow
Dim i As Integer
For i = 1 To 3
newRow1 = tCust.NewRow()
newRow1("custID") = i
' Add the row to the Customers table.
tCust.Rows.Add(newRow1)
Next i
' Give each customer a distinct name.
tCust.Rows(0)("custName") = "Customer1"
tCust.Rows(1)("custName") = "Customer2"
tCust.Rows(2)("custName") = "Customer3"

' Give the Current column a value.
tCust.Rows(0)("Current") = True
tCust.Rows(1)("Current") = True
tCust.Rows(2)("Current") = False
End Sub 'MakeDataSet

Regards,
Andrej
 
A

Andrej Radinger

Sorry, here is the rest, actually it is just setting datatable as a datagrid
datasource. Just add this code to the end of the previuos one.

Private myDataTable As DataTable
myDataTable = myDataSet.Tables("Customers")
dataGrid1.DataSource = myDataTable

Regards,

Andrej
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top