how do I link a datagridview to a dataset?

  • Thread starter Thread starter cj
  • Start date Start date
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.
 
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
 
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
 
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
 
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
 
Back
Top