New to Net but an old MSFlegrid user

CJParkes

New member
Joined
Jan 4, 2010
Messages
3
Programming Experience
1-3
I am new to this Forum and have been away from programming (VB6) for 5 years. Just starting "VBNet" I am concerned that VB6 user interfaces relied on the MSFlexgrid. I was able to manipulate Cols, Rows and cells with ease - Am I going to be be able to do the same in "VBNet" with the the Datagrid component ? or should I look for an alternative.
If the Datagrid will suffice any suggestions on books and help files/sites to get going on.
 
Thank you for your quick reply.
I clicked on your link with no luck and Googled the link - no luck - the site just hangs trying to load. Any other thoughts

CJParkes
 
The link works just fine for me.

Anyway, here is sample code from that link. The web site is vbdotnetheaven
VB.NET:
This article explains you how easy is reading a database and displaying in a grid using DataSet.

In this sample example, I have used access 2000 database, Northwind.mdb. We access Customers table of northwind database and display records in a datagrid control. 

Starting: Create a Windows Application type project and add a DataGrid control to the form. Leave DataGrid name as DataGrid1.

Add Reference to the Namespace

First thing you need to do is add reference to System.Data.OleDb namespace since I will use OldDb data providers. if System.Data namespace is not present, you might want to add this too.

Imports System.Data
Imports System.Data.OleDb

Create OleDbDataAdapter Object

Now you create a OleDbDataAdapter object and connect to a database table. 

' create a connection string
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Northwind.mdb"
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString 
' create a data adapter 
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Customers", myConnection)

Create a DataSet Object and Fill with the data

You use Fill method of OleDbDataAdpater to fill data to a DataSet object.

' create a new dataset 
Dim ds As DataSet = New DataSet
' fill dataset 
da.Fill(ds, "Customers")

Attach DataSet to DataGrid

Now you use DataSource method of DataGrid to attached the DataSet data to the data grid.

' Attach DataSet to DataGrid 
DataGrid1.DataSource = ds.DefaultViewManager 

Here is entire source code written on the form load method.

Imports System.Data
Imports System.Data.OleDb
' some code here 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' create a connection string 
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Northwind.mdb"
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString
' create a data adapter 
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Customers", myConnection)
' create a new dataset 
Dim ds As DataSet = New DataSet
' fill dataset 
da.Fill(ds, "Customers")
' write dataset contents to an xml file by calling WriteXml method 
' Attach DataSet to DataGrid 
DataGrid1.DataSource = ds.DefaultViewManager
End Sub
End Class
 
Great! Follow a tutorial that could be anything up to 9 years old, judging by the version of access..

Alternately, if you fancy using a modern tutorial, written by the same people who wrote the programming language youre using, refer to the DW2 link (Creating a Simple Data App section) in my signature, keeping an eye on the panel in the top right for any pages that are more relevant to the version of visual studio that you use...

One thing you need to really get down with is that grids DO NOT store data. The DataGridView component is merely a viewer, and some cells can invoke editor capabilities, but data is held elsewhere (a DataTable usually)
For more info on the generic concept, look up MVC (model view controller)
 
Back
Top