Currencymanager and finding underlying record i DB

  • Thread starter Finn Stampe Mikkelsen
  • Start date
F

Finn Stampe Mikkelsen

Hi

I'm a newbie to VB.NET.

I have an app, with a dataset called dsKunder1 containing several tables.
One being Reservedel....

I have a datagrid DgSpare, a dataview DvSpare, which i use to control the
dataview in my datagrid. I will be needing to use the rowfilter of the
dataview and then need to dbl-click on a row, accessing the underlying
actual datarow in the dataset, moving this to an datarow , so i can edit the
data...

I seem to understand, that i need to use a currencymanager, but i can't seem
to figure out how....

Pse, can anybody help??? Prefferably with an code example

/Finn
 
F

Finn Stampe Mikkelsen

Hi Cor...

It probably does, but i can't get the grip on that sniplett... I have tried
to convert it, but without luck.. Mainly because i don't understand the
concept of the Currencymanager other than it defines a link of some sorts

/Finn
 
C

Cor Ligthert [MVP]

Finn,

I assume this one
Dim cma As CurrencyManager = DirectCast(BindingContext(dt),
CurrencyManager)

CurrencyManager cma = (CurrencyManager)BindingContext[dt];

Cor
 
F

Finn Stampe Mikkelsen

Hi Cor....

Heres in details my project...:

I have a dataSet (dsKunder1) which contains 5 different datatables from the
same database. Of of them is Reservedel. I now have a form, with a Datagrid
(DgSpare), databinded to a Dataview (DvSpare), which in turn i databinded to
DsKunder1.Reservedel

When all my spareparts in the table Reservedel is listed in DgSpare, i can
doubleclick on any row and use

Dim CRow as datarow
Crow = dsKunder1.Reservedel.Rows(DgSpare.CurrentRowIndex)

And then access the row in CRow, edit and eventually update the database
with the new information....

As soon as i apply the RowFilter, the correspondance between CurrentRowIndex
and the actual RowIndex in DsKunder1.Reservedel is no longer assured and i
get wrong data in the above statement. i need to get the underlying
datatable row and here it seems to be the CurrencyManager that is to be
used... Bu how... That i can't se... being a newbie to VB.NET i can't
understand the different mechanisms used... I'm used to work with Delphi 7
and although it also has ADO functionallity, this is all done behind the
sceenes. Even whel using filters here, the actual position is given at any
time...

So i hope you can explain the application of currencymanager as potaining to
the above example...

/Finn
Cor Ligthert said:
Finn,

I assume this one
Dim cma As CurrencyManager = DirectCast(BindingContext(dt),
CurrencyManager)

CurrencyManager cma = (CurrencyManager)BindingContext[dt];

Cor

Finn Stampe Mikkelsen said:
Hi Cor...

It probably does, but i can't get the grip on that sniplett... I have
tried to convert it, but without luck.. Mainly because i don't understand
the concept of the Currencymanager other than it defines a link of some
sorts

/Finn
 
B

Bart Mermuys

Hi,

Finn Stampe Mikkelsen said:
Hi

I'm a newbie to VB.NET.

I have an app, with a dataset called dsKunder1 containing several tables.
One being Reservedel....

I have a datagrid DgSpare, a dataview DvSpare, which i use to control the
dataview in my datagrid. I will be needing to use the rowfilter of the
dataview and then need to dbl-click on a row, accessing the underlying
actual datarow in the dataset, moving this to an datarow , so i can edit
the data...

I seem to understand, that i need to use a currencymanager, but i can't
seem to figure out how....

* If you need to current underlying DataRow, then yes you can get it from
the CurrencyManager, but the "underlying row" is always a DataRowView (even
when bound to DataTable), from the DataRowView you can get the DataRow; eg:

' using the same DataSource as the one you used for binding
Dim cm As CurrencyManager = DirectCast(BindingContext(DvSpare),
CurrencyManager)

' if you want to be safe, you could also use:
Dim cm As CurrencyManager = DirectCast(BindingContext(dgSpare.DataSource,
dgSpare.DataMember), CurrencyManager)

' then you can get the current DataRowView:
Dim drv As DataRowView = DirectCast(cm.Current, DataRowView)

' from the DataRowView you can get the DataRow:
Dim dr as DataRow = drv.Row

* On the other hand, if you bind to a DataView, then the DataGrid indexes
are the same as the DataView, so you could simply use:
Dim drv As DataRowView = DvSpare(DgSpare.CurrentRowIndex)
Dim dr As DataRow = drv.Row



HTH,
Greetings
 
F

Finn Stampe Mikkelsen

Hi Bart

Great... It Works.... Thank you ever so much... I have programmed for
several year, but always in Pascal/Delphi and only recently in OOP. VB is
new to me and especially .NET, but i'm currently trying to get an MCSD /
MCAD using VB-NEt, so i must re-sattle my horse... Hi Hi

Once again... Thanks both to you and Cor for taking your time to help me

/Finn
 

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