DataBind - user type to change the Position

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thesti
    New Member
    • Nov 2007
    • 144

    DataBind - user type to change the Position

    hi,

    i'm going to develop a program using VB .NET.

    i've bound some textboxes to the same DataSource (DataSet1.Table s(0).
    and i enable the user to type the primaryKey of the data in the Table, so if the user has typed an existing PK in the table, the position of the CurrencyManager will be changed. in the 'KeyUp' event of the ID textBox, i implement this code

    Code:
    Private Sub txtID_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtID.KeyUp
            If txtID.Text = "" Then Exit Sub
    
            Dim index As Integer
            For index = 0 To DataSet1.Tables(0).Rows.Count - 1
                If CStr(DataSet1.Tables(0).Rows(index).Item("employeeID")) = txtID.Text Then
                    CType(BindingContext(DataSet1.Tables(0)), CurrencyManager).Position = index
                End If
            Next
    
            Debug.WriteLine(CStr(DataSet1.Tables(0).Rows.Count - 1) + " " + txtID.Text)
        End Sub
    then i try typing some existing PK in the table and a problem occurs, the data won't change if:
    1. i type "2", "3", "4" (any existing PK) then i go back to those i "have visited" like "1" or "2" or "3" the data won't change, but i does change if i type "6" or "7" or "8" (any row that i "haven't visited")

    2. i type "9", which is the last data in the Table. than i type any other PK like "7", "8", "1", "5". the data represented won't change.


    is there any probelm with my code ?

    thanks in advance.
  • thesti
    New Member
    • Nov 2007
    • 144

    #2
    hi,

    it seems i know what cause the problem.

    seems that because i also bound the txtID to the DataTable, so that when i type something in the txtID textbox, the underlying data is also changed.

    when the program runs, i'm in the firstrow. of which emplooyeID is "1", then i type "2", the employeeID value for the firstRow is changed to "2". that's why i couldn't go back to "1".

    is there any workaround for this? because i have a prev, next button to let the user iterates the data. if the txtID is not bound, then it's text won't be updated as the user presses the button.


    thanks

    Comment

    Working...