By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,838 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,838 IT Pros & Developers. It's quick & easy.

DataBind - user type to change the Position

100+
P: 144
hi,

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

i've bound some textboxes to the same DataSource (DataSet1.Tables(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

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtID_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtID.KeyUp
  2.         If txtID.Text = "" Then Exit Sub
  3.  
  4.         Dim index As Integer
  5.         For index = 0 To DataSet1.Tables(0).Rows.Count - 1
  6.             If CStr(DataSet1.Tables(0).Rows(index).Item("employeeID")) = txtID.Text Then
  7.                 CType(BindingContext(DataSet1.Tables(0)), CurrencyManager).Position = index
  8.             End If
  9.         Next
  10.  
  11.         Debug.WriteLine(CStr(DataSet1.Tables(0).Rows.Count - 1) + " " + txtID.Text)
  12.     End Sub
  13.  
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.
Oct 11 '08 #1
Share this Question
Share on Google+
1 Reply


100+
P: 144
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
Oct 13 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.