very novice Find Button

  • Thread starter Thread starter KentL
  • Start date Start date
K

KentL

I have a DataForm bound to a dataSet "dsPhoneBook". I want to have a button
"btnFind"on my form open a input box where I can enter a name and the record
be set to the name I entered into the input box. I can not figure out how
to do this. Need Help!
Thanks
Kent
 
I assume you have the input box part down. You can bind your grid or
controls to either a DataTable or a Datview. They have a few methods
between the two of them, like DataView.RowFilter, Find, Select that you can
call with the value of the input box. If you look over at
http://www.knowdotnet.com/williamryan.html under Effieciently Using ADO.NET
v 1-4, I have examples of how to use both the DataTable and the DataView and
their matching methods above locate and find data. Once you have the rows
you can show them in controls you just cleared or you can let the bindings
handle it, kind of depends on how you want to display it, but the big
challenge is finding the data.

If you have trouble with getting the found data to display, just tell me
which method you used and what you need to display evertyhing in, a
Datagrid, textboxes, both etc.

HTH,

Bill

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
 
Thanks for the help William
I'm using a DataTable. The code I have for the Find Button is below. I
can't get it to move to the record, if it is even finding it. I only have
two fields in the table, Name and Number. With Number being the Primary
Key. I don't think I am referencing the field correctly or something. Your
help would be appreciated.
Thanks!
Kent

Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnFind.Click

Dim message, title, defaultValue As String

Dim findName As String

message = "Enter the name!"

title = "Find Name"

defaultValue = ""

findName = InputBox(message, title, defaultValue, 500, 400)

Me.objdsPhoneBok.Tables("tblPhoneBook").Rows.Find(findName)

End Sub
 
I'd use A dataview and set the rowfilter instead.. Just bind your controls
to the Dataview instead of the datatable

Dim dv as DataView = Me.objdsPhoneBok.Tables.DefaultView
Dim findName As String
message = "Enter the name!"

title = "Find Name"

defaultValue = string.Empty
findName = InputBox(message, title, defaultValue, 500, 400)
If (findName <> string.Empty) Then
dv.RowFilter = "WhateverFieldfindNameBelongsTo = '" & findName & "'"
End If

depending on how your app works, you may want to make them put in a vavlue,
but if they choose nothing, don't waste any time trying to do anything.

HTH,

Bill




--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
http://www.devbuzz.com/content/zinc_personal_media_center_pg1.asp
 
Back
Top