|
-
Jul 24th, 2008, 12:31 AM
#1
Thread Starter
Addicted Member
Need help with 'Find' coding
I am trying to implement a Find button in my form.
There are 2 text boxes : one for part code and the other for part seq number and 2 Find buttons, one for each of the above.
Here is my code:
Code:
Public Class MRP_Planning
Private Sub Part_Planning_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.PartsTableAdapter.Fill(Me.PartDataSet.Parts)
End Sub
Private Sub btnFindSeqNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindSeqNo.Click
Dim indexNumber As Integer = Me.PartsBindingSource.Find("SequenceNumber", Me.FindBySequenceNo.Text)
Me.PartsBindingSource.Position = indexNumber
End Sub
Private Sub btnFindPartCode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindPartCode.Click
Dim indexNumber As Integer = Me.PartsBindingSource.Find("PartCode", Me.FindByPartCode.Text)
Me.PartsBindingSource.Position = indexNumber
End Sub
End Class
Is it possible for me to set the code where there is only 1 button and 1 textbox that the code will read the input values of part code and seq number?
-
Jul 24th, 2008, 12:43 AM
#2
Re: Need help with 'Find' coding
And then how will the app know whether to search for a part number or sequence number?
-
Jul 24th, 2008, 12:54 AM
#3
Thread Starter
Addicted Member
Re: Need help with 'Find' coding
Sorry my mistakes. It's 1 button and 2 textboxes. Will that still be possible?
-
Jul 24th, 2008, 01:03 AM
#4
Re: Need help with 'Find' coding
So you want to search for both at the same time, or just one TextBox will be populated at a time?
-
Jul 24th, 2008, 01:14 AM
#5
Thread Starter
Addicted Member
Re: Need help with 'Find' coding
If possible, I like it to search both at the same time...
-
Jul 24th, 2008, 01:37 AM
#6
Re: Need help with 'Find' coding
That's a bit tricky. The BindingSource only supports searching by one column at a time. You could search the underlying DataTable:
vb.net Code:
Dim rows As DataRow() = myDataTable.Select(String.Format("SequenceNumber = '{0}' AND PartCode = '{0}'", _ Me.FindBySequenceNo.Text, _ Me.FindByPartCode.Text), _ myBindingSource.Filter) If rows.Length > 0 Then For index As Integer = 0 To myBindingSource.Count - 1 If DirectCast(myBindingSource(index), DataRowView).Row = rows(0) Then myBindingSource.Position = index Exit For End If Next End If
-
Jul 24th, 2008, 02:07 AM
#7
Thread Starter
Addicted Member
Re: Need help with 'Find' coding
I gotten 2 errors while inputting the above code.
1. Name 'myDataTable' is not declared
2. Operator '=' is not defined for types 'System.Data.DataRow' and 'System.Data.DataRow'
How do I rid of the errors?
-
Jul 24th, 2008, 02:42 AM
#8
Re: Need help with 'Find' coding
1. Say it to yourself: "myDataTable". What do you suppose that refers to? That code is an EXAMPLE. You have to adapt it to YOUR project, so you have to use YOUR DataTable. Don't just copy and paste blindly. Look, read and think about what the code is actually doing.
2. That one's my fault. It should be 'Is' instead of '='.
-
Jul 24th, 2008, 02:59 AM
#9
Thread Starter
Addicted Member
Re: Need help with 'Find' coding
datatable as in? Is it the data source that I bind it to?
-
Jul 24th, 2008, 04:42 AM
#10
Re: Need help with 'Find' coding
This:
Code:
Me.PartsTableAdapter.Fill(Me.PartDataSet.Parts)
is YOUR DataTable.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|