Results 1 to 7 of 7

Thread: BindingSource.Position issue

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Question BindingSource.Position issue

    Hi,

    I am using the following code to populate data in Textbox1:

    Code:
    Me.OrdersTableAdapter.Fill(Me.OrderBookingDataSet.Orders, Master.c)
    Me.OrdersBindingSource.Position = OrdersBindingSource.Find("ord", Master.o)
    I have few functions assigned in TextBox1_TextChanged event. The problem i am facing is this event is fired twice, once after the Fill command and another after the Position command whereas i want the event to fire only once after the Position command. What should i do?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: BindingSource.Position issue

    You should either not bind until after setting the Position or else ignore the first event. If you want to ignore the first then you must know that it's the first event, which would require a Boolean flag. Set it first, then reset it afterwards.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: BindingSource.Position issue

    I would like to set the position before binding. how can i do that?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: BindingSource.Position issue

    Quote Originally Posted by LuxCoder View Post
    I would like to set the position before binding. how can i do that?
    Set the Position property first, then bind the BindingSource to the control(s).
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: BindingSource.Position issue

    This doesn't work.

    Code:
    Me.OrdersBindingSource.Position = OrdersBindingSource.Find("ord", Master.o)
    Me.OrdersTableAdapter.Fill(Me.OrderBookingDataSet.Orders, Master.c)

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: BindingSource.Position issue

    Of course that doesn't work. You're trying to set the Position before you've populated the DataTable. If you haven't populated the DataTable with data then how can you Find anything in the data it contains? Populate the DataTable, bind the DataTable to the BindingSource, set the Position, bind the BindingSource to the control(s).
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: BindingSource.Position issue

    This works

    Code:
    RemoveHandler TextBox1.TextChanged, AddressOf TextBox1_TextChanged
    Me.OrdersTableAdapter.Fill(Me.OrderBookingDataSet.Orders, Master.c)
    AddHandler TextBox1.TextChanged, AddressOf TextBox1_TextChanged
    Me.OrdersBindingSource.Position = OrdersBindingSource.Find("ord", Master.o)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width