Currency Manager

U

uknees

Hi people,

I am trying to use a currency manager on a master-detail windows
form.

However, I just can't seem to scroll the records.

here's my code:
'setting relation of datatables
ds.Relations.Add("CustOrd",ds.Tables!Cust.Columns!CustomerID,_
ds.Tables!Orders.Columns!CustomerID)


'after binding data to textbox fields and datagrid
cm=CType(Me.BindingContext(ds.Tables!Cust),CurrencyManager)

'scrolling to first record
If Not (cm Is Nothing) AndAlso cm.Count Then cm.Position = 0
'scrolling to next record
If Not (cm Is Nothing) AndAlso cm.Count AndAlso cm.Position
<cm.Count -1 Then cm.Position +=1
'scrolling to Previous record
If Not (cm Is Nothing) AndAlso cm.Count AndAlso cm.Position >0 Then
cm.Position -=1
'scrolling to Last record
If Not (cm Is Nothing) AndAlso cm.Count Then cm.Position=cm.Count-1

Can anyone help?
 
M

Miha Markic

Hi,

What is your problem?
Can't get currencymanager?
Is there an error you are getting?

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

uknees said:
Hi people,

I am trying to use a currency manager on a master-detail windows
form.

However, I just can't seem to scroll the records.

here's my code:
'setting relation of datatables
ds.Relations.Add("CustOrd",ds.Tables!Cust.Columns!CustomerID,_
ds.Tables!Orders.Columns!CustomerID)


'after binding data to textbox fields and datagrid
cm=CType(Me.BindingContext(ds.Tables!Cust),CurrencyManager)

'scrolling to first record
If Not (cm Is Nothing) AndAlso cm.Count Then cm.Position = 0
'scrolling to next record
If Not (cm Is Nothing) AndAlso cm.Count AndAlso cm.Position
<cm.Count -1 Then cm.Position +=1
'scrolling to Previous record
If Not (cm Is Nothing) AndAlso cm.Count AndAlso cm.Position >0 Then
cm.Position -=1
'scrolling to Last record
If Not (cm Is Nothing) AndAlso cm.Count Then cm.Position=cm.Count-1

Can anyone help?



----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=---
 
U

uknees

There's no error. My problem is that the scroll position is correct
because i checked it with a msgbox. But, the data does not display at
the correct position. in fact, the data doesn't move at all!

any idea why?
 
M

Miha Markic

You are probalbly gettin wrong cm.
How do you bind datasource to controls?

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

uknees said:
There's no error. My problem is that the scroll position is correct
because i checked it with a msgbox. But, the data does not display at
the correct position. in fact, the data doesn't move at all!

any idea why?



----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=---
 
K

Kathleen Dollard

Just to clarify where Miha is going with his questions....

When you access a currency manager that doesn't already exist, WinForms will
create one for you. This makes it extremely easy to have one currency
manager in use to display data, and a totally separate curerncy manager that
you're moving in, or that is attached to a second set of controls. Problems
often originate in what you specify as DataSource and DataMember. If you are
defining your binding to fields via the property dialogs, it would be
easiest to help you if you search for one of the controls that isn't working
in the hidden Windows.Forms region, and copy the code that does the
databinding (it will be much easier to read if you paste it into Notepad,
then copy it from Notepad into your message). You can include the
surrounding several lines of code for context. Then also post how you are
retrieving the currency manager. Once you see these side by side, your
solution may be obvious. Note that you'll want to change the code rerieving
the currency manager, not the hidden Windows.Forms code.

--
Kathleen Dollard
Microsoft MVP
Author "Code Generation in Microsoft .NET"


uknees said:
Hi people,

I am trying to use a currency manager on a master-detail windows
form.

However, I just can't seem to scroll the records.

here's my code:
'setting relation of datatables
ds.Relations.Add("CustOrd",ds.Tables!Cust.Columns!CustomerID,_
ds.Tables!Orders.Columns!CustomerID)


'after binding data to textbox fields and datagrid
cm=CType(Me.BindingContext(ds.Tables!Cust),CurrencyManager)

'scrolling to first record
If Not (cm Is Nothing) AndAlso cm.Count Then cm.Position = 0
'scrolling to next record
If Not (cm Is Nothing) AndAlso cm.Count AndAlso cm.Position
<cm.Count -1 Then cm.Position +=1
'scrolling to Previous record
If Not (cm Is Nothing) AndAlso cm.Count AndAlso cm.Position >0 Then
cm.Position -=1
'scrolling to Last record
If Not (cm Is Nothing) AndAlso cm.Count Then cm.Position=cm.Count-1

Can anyone help?



----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=---
 
U

uknees

Sorry Kathleen,

I don't really get what you mean, I am not very fluent with .Net
Anyway, here's my code on databinding right from the top

I declare the currency manager right after the inherit form code
Inherits System.Windows.Forms.Form
Dim cm As CurrencyManager

'Databinding Sub
Dim da As SqlDataAdapter = New SqlDataAdapter(myCommand)
Dim da_sched As SqlDataAdapter = New
SqlDataAdapter(myCommand)
Dim da_bomitem As SqlDataAdapter = New
SqlDataAdapter(myCommand)
Dim inRid, inBomID As SqlParameter

myCommand.CommandText = "Select * from mat_plan_sched_mst order
by rid"
myCommand.CommandType = CommandType.Text
myCommand.Connection = Conn1

da.Fill(ds, "Schedule")

intRid =
ds.Tables("Schedule").Rows(0).Item("rid")

inRid = New SqlParameter("@Rid", SqlDbType.BigInt)
inRid.Direction = ParameterDirection.Input
inRid.Value = intRid
'ds.Tables("Schedule").Rows(0).Item("rid")

inBomID = New SqlParameter("@BomId",
SqlDbType.BigInt)
inBomID.Direction = ParameterDirection.Input
inBomID.Value = intRid
'ds.Tables("Schedule").Rows(0).Item("rid")

myCommand.CommandText = "Select * from mat_plan_sched_dtl where
mat_plan_sched_dtl.rid = @RID"
myCommand.CommandType = CommandType.Text
myCommand.Connection = Conn1
myCommand.Parameters.Add(inRid)

da_sched.Fill(ds, "Details")

myCommand.CommandText = "Select * from bomitem where rid in
(select bomid from mat_plan_sched_dtl where rid =
@BomId)"
myCommand.CommandType = CommandType.Text
myCommand.Connection = Conn1
myCommand.Parameters.Add(inBomID)

da_bomitem.Fill(ds, "BomItem")

'Build the relation between Schedule and schedule_dtl
ds.Relations.Add("Mst_Sched",
ds.Tables!Schedule.Columns("rid"),
ds.Tables!Details.Columns("rid"))
ds.Relations.Add("Bom Items",
ds.Tables!Details.Columns("bomid"),
ds.Tables!BomItem.Columns("rid"))

'Bind data
txtRefNo.DataBindings.Add("Text", ds,
"Schedule.ref_no")
txtRid.DataBindings.Add("Text", ds,
"Schedule.rid")
txtPlanner.DataBindings.Add("Text", ds,
"Schedule.mat_planner")
txtRemarks.DataBindings.Add("Text", ds,
"Schedule.remarks")
cmbEmployee.DataBindings.Add("Text", ds,
"Schedule.bdd_req")
dtpReqDate.DataBindings.Add("Text", ds,
"Schedule.req_date")

dgItems.SetDataBinding(ds, "Details")

cm = CType(Me.BindingContext(ds.Tables!Schedule),
CurrencyManager)
'Show Last Record
cm.Position = cm.Count - 1

'**************** Format Gridstyle code
'End Sub

'The following are the navigation code

Private Sub miFirst_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles miFirst.Click
If Not (cm Is Nothing) AndAlso cm.Count Then
cm.Position = 0
End Sub

Private Sub miNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles miNext.Click
If Not (cm Is Nothing) AndAlso cm.Count AndAlso cm.Position
< cm.Count - 1 Then cm.Position = cm.Position + 1
End Sub

Private Sub miPrevious_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles miPrevious.Click
If Not (cm Is Nothing) AndAlso cm.Count AndAlso cm.Position
0 Then cm.Position -= 1
End Sub

Private Sub miLast_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles miLast.Click
If Not (cm Is Nothing) AndAlso cm.Count Then cm.Position =
cm.Count - 1
End Sub


How will I know if I am accessing a currency manager that doesn't
exist? Wouldn't there be an error?

Please advise. Thanks.
 
U

uknees

I replaced all cm(currency manager) with this Me.BindingContext(ds,
"Schedule") and the scrolling works.

Except that, it only works for the textboxes which are bound to the
datatable "Schedule". With a relation set in the dataset(ds) why
doesn't the datagrid(which is bound to datatable "Details") scroll to
the details accordingly?

ds.Relations.Add("Mst_Sched",
ds.Tables!Schedule.Columns("rid"),
ds.Tables!Details.Columns("rid"))

txtRefNo.DataBindings.Add("Text", ds,
"Schedule.ref_no")
txtRid.DataBindings.Add("Text", ds,
"Schedule.rid")
txtPlanner.DataBindings.Add("Text", ds,
"Schedule.mat_planner")
txtRemarks.DataBindings.Add("Text", ds,
"Schedule.remarks")
cmbEmployee.DataBindings.Add("Text", ds,
"Schedule.bdd_req")
dtpReqDate.DataBindings.Add("Text", ds,
"Schedule.req_date")

dgItems.SetDataBinding(ds, "Details")

Me.BindingContext(ds, "Schedule").Position =
Me.BindingContext(ds, "Schedule").Count - 1
 

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