Binding Manager Position

  • Thread starter Thread starter Bob Ranck
  • Start date Start date
B

Bob Ranck

This is a follow response to questions raised by
Kathleen Dollard.

The Original problem was Binding Manager refuses to
position on the proper row after an ADDNEW.

This is the BindingManager wont go to Row 9 Problem.

If you look for the comments on the Debug lines you can
see that the progress in count and position. We are
adding a 10th Row to this dataview.

Here is the NewCustomerRow Functions from my
DataAccessLayer

Friend Sub AddNewCustomer()
Dim newCustomer As LProDataSet.CustomerRow
newCustomer = CType(AddRowThroughBinding().Row,
LProDataSet.CustomerRow)
newCustomer.BeginEdit()
newCustomer.CompanyName = ""
newCustomer.Address1 = ""
newCustomer.City = ""
newCustomer.ST = ""
newCustomer.Zip = ""
newCustomer.ContactLastName = ""
newCustomer.Phone1 = ""
newCustomer.EndEdit()
End Sub
Private Function AddRowThroughBinding() As DataRowView
Try
Debug.WriteLine(m_DalBindingManager.Count)
'If this view was filtered this might be 3 Rows
Debug.WriteLine(m_DalBindingManager.Position)
'and this might be 2
'Kill any edits
DaLBindingManager.EndCurrentEdit()
'Kill any Filters
Me.FilterThroughBinding("")
Debug.WriteLine(m_DalBindingManager.Count)
'Now I have a count of all Nine Rows
Debug.WriteLine(m_DalBindingManager.Position)
'and its pointing to 0
'Add the New Row
DaLBindingManager.AddNew()
Debug.WriteLine(m_DalBindingManager.Count)
'Success I have 10 Rows
Debug.WriteLine(m_DalBindingManager.Position)
'But darn its pointing to 0 instead of 9
'Kill the Edit before Returning the RowView
DaLBindingManager.EndCurrentEdit()
Debug.WriteLine(m_DalBindingManager.Count)
m_DalBindingManager.Position =
m_DalBindingManager.Count - 1 'No help - still points to 0
Debug.WriteLine(m_DalBindingManager.Position)
Return CType(DaLBindingManager.Current,
DataRowView)
Catch ex As System.Exception
MessageBox.Show("Error: " & ex.Message, "Add
New Error", MessageBoxButtons.OK, MessageBoxIcon.Error,
MessageBoxDefaultButton.Button1)
End Try
End Function

Thank You
 
Kathleen,
The Form that I am using has some bound controls
and some other controls which are programaticaly
connected to the same dataview

Your Prior advice helped me find the problem
When the ADDNEW took place in the DAL the
value in one of the text boxes on the form
being serviced by the DAL (Consumer?)changed

I think I found a second No-No. My discovery is: from the
time an ADDNew is initiated in the DAL Until the
Return CType(DaLBindingManager.Current,DataRowView)
statement takes place, you must prevent the form from
referencing a field in the dataview. This is what
"locked up" my binding manager. My Fix was to make
an AddRowInProgress boolean to stop bad things.

This was a really tough problem! Thanks, your advice
helped.

Could you help with two more things.

What is a Best Practice way to Bind a set of Radio
buttons to a single column?

I have all the ADO.Net Books but no one has written
much about real life binding. Everything I
have seen uses very simple examples - just enough to
get you in trouble. For example: what is the best
way to work with code and bind on the same form with
the same dataview?
the same
 
Back
Top