help with currencymanager position

G

Guest

I want to access hidden columns in a datagrid as soon as the row is changed
so that I can alter some aspects of my form. To do this I need to access the
approriate row in the underlying datatable so I can "see" the hidden data. To
get the correct row I tried using

me.bindingcontext(underlyingtable).position

but it gives me 0 no matter what cell I'm on. All the bound controls update
properly. When I use a Watch to look at the currency manager it seems OK (it
has the correct number of rows), so I don't understand what the issue is. I
have several work arounds, but I would really like to know what is wrong with
this approach.
 
G

Guest

Consider the following two statements, where ds1 is a strongly typed dataset
and dt1 is a table in ds1. then

Dim cma As CurrencyManager = DirectCast(BindingContext(ds1.dt1),
CurrencyManager)

does not work, but

Dim cmb As CurrencyManager = Me.BindingContext(ds1, "dt1")

does. If dt2 is a sub table of dt1 then the correct way to reference it is

Dim cmb As CurrencyManager = Me.BindingContext(ds1, "dt1.dt1_dt2")

I am not at all clear on the difference between
ds1.dt1 (which doesn't work) and the examples in the books that would go like
ds1.tables("dt1") both of which are of type form.ds1.dt1Datatable. Perhaps
someone can explain this to me.
 
B

Bart Mermuys

Hi,

rossu said:
Consider the following two statements, where ds1 is a strongly typed
dataset
and dt1 is a table in ds1. then

Dim cma As CurrencyManager = DirectCast(BindingContext(ds1.dt1),
CurrencyManager)

does not work, but

Dim cmb As CurrencyManager = Me.BindingContext(ds1, "dt1")

does. If dt2 is a sub table of dt1 then the correct way to reference it
is

Dim cmb As CurrencyManager = Me.BindingContext(ds1, "dt1.dt1_dt2")

I am not at all clear on the difference between
ds1.dt1 (which doesn't work) and the examples in the books that would go
like
ds1.tables("dt1") both of which are of type form.ds1.dt1Datatable.
Perhaps
someone can explain this to me.

Notice that the parameters for BindingContext(..) are DataSource and
DataMember. DataSource needs to be exactly the same as the one you used for
the binding and DataMember too (excluding field, so it can be empty and may
be omitted).

It's just the way it is. A BindingContext is a map, where the key is a
composed key [DataSource, DataMember] and the value is a CurrencyManager or
PropertyManager. So only if you use the right key, you'll get the right
CurrencyManager. (And if the key doesn't exists yet, it will create a new
CurrencyManager/PropertyManager and add the key).

When you bind to a DataTable, you use a DataTable to get the
CurrencyManager, when you bind to a DataSet you use the DataSet to get the
CurrencyManager, etc...


HTH,
Greetings
 

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