how do I link a datagridview to a dataset?

C

cj

In VB 2008 how do I link the datagridview to a dataset?

mydataadapter.fill(myds, "test")
datagridview1.????????

When I was using 2005 I used the datagrid and it was done like:

mydataadapter.fill(myds, "test")
datagrid1.DataGrid1.SetDataBinding(ds, tableName)

but in 2008 with the datagridview setdatabinding doesn't exist.
 
J

Jack Jackson

In VB 2008 how do I link the datagridview to a dataset?

mydataadapter.fill(myds, "test")
datagridview1.????????

When I was using 2005 I used the datagrid and it was done like:

mydataadapter.fill(myds, "test")
datagrid1.DataGrid1.SetDataBinding(ds, tableName)

but in 2008 with the datagridview setdatabinding doesn't exist.

DataGridView1.DataSource = myds
 
R

Rich P

I had problems using databinding so I just did this:

datagridview1.dataSource = dataset1.Tables("stevedog")

and you can set a currencyManager object like this

dim curMg As CurrencyManager

curMgr = Ctype(Me.BindingContext(dataset1.Tables("stevedog"),
CurrencyManger)

CurMgr.Position = 0
txtPos.Text = (CurMgr.Position + 1).ToString
txtCount.Text = CurMgr.Count.ToString

You can increment CurMgr like this

CurMgr.Position += 1

in the Click event of the datagridview or in the RowEnter event.



Rich
 
R

Rich P

I had problems using databinding so I just did this:

datagridview1.dataSource = dataset1.Tables("stevedog")

and you can set a currencyManager object like this

dim curMg As CurrencyManager

curMgr = Ctype(Me.BindingContext(dataset1.Tables("stevedog"),
CurrencyManger)

CurMgr.Position = 0
txtPos.Text = (CurMgr.Position + 1).ToString
txtCount.Text = CurMgr.Count.ToString

You can increment CurMgr like this

CurMgr.Position += 1

in the Click event of the datagridview or in the RowEnter event.



Rich

Rich
 
C

Cor Ligthert[MVP]

cj.

The datasource in the DataGridView exist from version 2005, it exist in the
DataGrid, the ListBox and the Combobox from version 2002.

However, in version 2008 it is better to place the bindingsource between it
as some problems are then fixed while behaviour in old programs stay the
same.

\\\
Dim bs As New BindingSource
bs.DataSource = dt
DataGridView1.DataSource = bs
////

Cor
 

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