Sorry to Re-Post - Databindings problem

  • Thread starter Thread starter MadCrazyNewbie
  • Start date Start date
M

MadCrazyNewbie

Hey Group,

Sorry but i`ve been searching everywhere for this even went out and bought a
ADO book and still carn`t find what im looking for:(

I have the following code for my postion changed:

Private Sub objdsAccess_PositionChanged()
If Me.BindingContext(objdsAccess, "Users").Position <> -1 Then
Me.ComboBox1.SelectedValue =
objdsAccess.Users.Rows(Me.BindingContext(objdsAccess,
"Users").Position).Item("AccessLevelID")
End If
Me.lblNavLocation.Text = (((Me.BindingContext(objdsAccess,
"Users").Position + 1).ToString + " of ") + Me.BindingContext(objdsAccess,
"Users").Count.ToString)
End Sub

This works fine, with my Combo Box. My ComboBox is using the following code:

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If Me.BindingContext(objdsAccess, "Users").Position <> -1 And Not
mlLoading Then
objdsAccess.Users.Rows(Me.BindingContext(objdsAccess,
"Users").Position).Item("AccessLevelID") = Me.ComboBox1.SelectedValue
End If
End Sub

This all works fine, if im using Navigation buttons and calling:
Me.objdsAccess_PositionChanged().

However I`ve now added a Datagrid to my Form, as I select a Row in my form.
How would i get it to update my ComboBox, and notice the position changed?

Thanks
MCN
 
If they are associated with the same currency manager it will do it
automatically.

However, the probably isn't the case. anyways, in ADO.NET you have these
things called CurrencyManagers that basically act kinda like an old
ADODB.Recordset (yes like many things in .NET). Anyways, CurrencyManagers
are created from bindings (actually you get them from the bindingContext of
the control).

This CurrencyManager is automatically subscribed the the datagrid events (or
vise versa, either way, upon changing the position in a datagrid (i.e moving
to a new row) the currency managers position is changed for you and an event
is fired.

so the best way to handle this is.

In your class delcaration do this...

Private WithEvents _cmMyDataset as CurrencyManager

Then in your form load (best place I think, you can do it others like in
your constructor, but not really a big deal.

_cmMyDataSet = BindingContext(myDataSource, "myDataTable")

Obviously replace those with valid values for your dataset and datatable.

Then, in your property browser on the top left (the drop down) you can find
the variable _cmMyDataSet Variable and the events associated with it on the
right.

Subscribe to the PositionChanged event, and then you can do whatever you
want. (i.e something with your combobox based on new row data).

CurrencyMangers are also INCREDIBLY useful when doing record manipulation,
because you can actually turn off the binding using the .SuspendBinding()
and .ResumeBinding() methods, so if your working with large lists (i.e.
filling a large dataset) you can use suspendbinding while your filling it
(otherwise, every time an item is added it goes through the process of
repainting a control because of the ListChanged event on an IListSource
item.

HTH,
CJ
 
Hey CJ,

Hows you doing?

Right i`ve added Private WithEvents cmDsAccess As CurrencyManager in my
Class Decleration and then added cmDsAccess = BindingContext(objdsAccess,
"Users") in my form load.

How would i now get it to change my bindings on my textboxs, and Combo box
as i select rows in my Datagrid?

ManyThanks
MCN(Si)

By Datasource, do you mean the
 
Simon,

since you declared your cmDsAccess WithEvents you can look up in the top
left dropdown where it describes all you objects etc (like textboxes and so
on).

in there you will see your cmDsAccess object. If you click on it, you'll
see the events on the right side combo box. One of those will be position
changed.

click it (subscribing to it) and then that is your notifcation that the row
position has changed within your datagrid. At that point, you can do
whatever you want. for exmaple, on your position chaged event you can get
the current row from the currency manager (cmDsAccess.Current()) and
maniuplate your combo boxes based off that.

How are things? Things are busy as sh**

=)

-CJ
 
CJ

Im not to bad been really busy with work and wot not:( All work and no
play:(

Anyways ....... I`ve looked in my propery Browser but i carn`t seem to find
cmDsAccess anywhere in there:(

Any Ideas?

Ta
MCN(Si)
 
Go to your Code Window... Look at the combo box on the top left side.. you
can't miss it.. there are two of them. right above your code. look there.
=)
 
Sorry CJ, I Must be going blind.

I think im going mad aswell and probably missing the point:(

How do i get it to do my positions changed? I have my Nav buttons setup to
call: Me.objDsAccess_PositionChanged.

My Position Change code is as follows:

Private Sub objdsAccess_PositionChanged()
If Me.BindingContext(objdsAccess, "Users").Position <> -1 Then
Me.ComboBox1.SelectedValue =
objdsAccess.Users.Rows(Me.BindingContext(objdsAccess,
"Users").Position).Item("AccessLevelID")
End If
Me.lblNavLocation.Text = (((Me.BindingContext(objdsAccess,
"Users").Position + 1).ToString + " of ") + Me.BindingContext(objdsAccess,
"Users").Count.ToString)
End Sub

How do i get this to work for my Datagrid. Do I need a:
Datagrid1_SelectedIndexChanged. Sorry i don`t know where to call a datgird
PostionChanged from or am I barking up the wrong tree?

Sorry to be a pain.

Cheers
MCN(Si)
 
Killin me dog.

Alright, lets back it up a little bit. =)

1) objdsAccess_PositionChanged()

How is this called? what causes this to be called.?



2) Me.BindingContext(objdsAccess, "Users").

that right there is a currency manager. you can assign a variable to it,
makes things easier. Is your datagrid bound to this datatable on the
objDsAccess? what table is it bound to?
 
From my Nav buttons I call objDsAccess_PostitionChanged() for example:

Private Sub btnNavFirst_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNavFirst.Click
Me.BindingContext(objdsAccess, "Users").Position = 0
Me.objdsAccess_PositionChanged()
End Sub

My Datatable is bound to objdsAccess.Users.

I have a relationship Setup from my Users Table, AccessID row to my
AccessLevel Table AccessID.

My AccessLevelID Table has a AccessLevel Feild in it to which my ComboBox
Looks at.

Ta
MCN(Si)
 
Simon,

Alright, in your form load create a currency manager (using your
_cmDsAccess) with

_cmDsAccess = BindingContext(objdsAccess, "Users")

now you previously declared this as

private WithEvents _cmDsAccess as CurrencyManager

then you want to create a method such as

Private Sub _cmDsAccess_PositionChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles _cmDsAccess.PositionChanged





inisde this method is where you want to do

objdsAccess_PositionChanged()

try it out.



-CJ
 
CJ,

I`ve done the below but with no joy:(

i`ve mailed you privatly with my App attached, i tryed to post my App here
(60kb) but it dosn`t seem to want to post:(

Cheers
MCN(Si)
 
simon, give me some time to get it... may not be till tonight. can't access
home email from here.
 
Back
Top