Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2004

Tip: Looking for answers? Try searching our database.

Datagrid findfirst findnext

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Hernry - 30 Oct 2004 05:29 GMT
I have been watching the dotnet newsgroups for a couple of weeks now and
scouring the net looking for a solution to my datagrid find functionality.
With no luck.  I am hoping that you can help me.

I am an old VB6 coder used to using Sheridan controls, and I am just
starting to learn the .net world.

I am upgrading my music catalogue database, where the data is stored in an
Access mdb file.

The datagrid is bound to a dataview and I can get the find to work in that
it returns a valid row, but it is not the first row with that value.

Here is my search code
Dim dvData As DataView

Dim cmBkMrk As CurrencyManager

Dim intRec As Integer

dvData = Me.dgrCatalogue.DataSource

dvData.Sort = "Artist"

cmBkMrk = Me.dgrCatalogue.BindingContext(dvData)

intRec = dvData.Find("Triumph")

cmBkMrk.Position = intRec

It is finding the band Triumph, and moving to the found row, but it is not
the first row with the value Triumph.  Why?

While I am here, I have three  more questions:

1) How do I perform a FindNext?

2) How do I perform wildcard searches?

3) How do I perform searches on more than one column?  I have figured out
how to sort on two columns, but what is the dvData.Find code?

Thanks In Advance!

Greg
Cor Ligthert - 30 Oct 2004 08:29 GMT
John,

I know that the dataview.find exist hower I did never use that one,
(probably because for that one the datarowcollection.find does(is) the same
and is easier to handle.

I think that you want more rows back and than the datarowfilter is easier to
handle.

The datarowfilter you set by (Keep in mind that the rowfilter is dynamicly
and reacts direct on the change of a filterfield) All is typed by hand in
this message so watch typos

\\\
dv.rowfilter = "MyFirstFindColomn = 'Whatever' AND MySecondColumn =
'SometingElse'"
//
(Mostly you have to make dynamicly a concatenated string, Think than to
enclose those in single quotes for string fields
\\\
For Each dvv As DataRowView In dv
           dvv(0) = "Myfield"
Next
///
Or if you want that
\\\
For i as integer = 0 to dv.count-1
     dv(i)(0) = "Myfield"
Next
///
I hope this helps?

Cor

"John Hernry" <john.henry@sasktel.com>
>I have been watching the dotnet newsgroups for a couple of weeks now and
>scouring the net looking for a solution to my datagrid find functionality.
[quoted text clipped - 41 lines]
>
> Greg
John Hernry - 30 Oct 2004 16:20 GMT
Cor,
Thanks for the response.  I have seen your responses to these type of
questions before and I was hoping you would respond.

Unfortunately, though, the filter isn't really what I'm after.  I really
would like to keep all of the data visible so that the user can scroll
around in curiosity if need be.  If you have ever used the find in Access I
am trying to build something along that line.  Where I can specify criteria
such as: search in one field, all fields, at the beginning of the field, end
of the field, must match the entire field, or case sensitive etc.  I suspect
that I am going to have to iterate through each field of each row based on
the search criteria.  I was hoping for a quicker method as this method will
be slow.  My database currently has 30,000 records with 5 fields: ID,
Source, Song, Artist, Album.

I have tried the filter method, and it would work as a last resort, but
ultimately it isn't what I'm after.  Any other suggestions?

John

> John,
>
[quoted text clipped - 76 lines]
>>
>> Greg
Cor Ligthert - 30 Oct 2004 19:06 GMT
John,

When I started reading your question I thought, impossible and than I
thought, stupid me, of  course that should be possible, probably a second
dataview will do exactly as you are asking for.

You can create as much dataviews you want from the same datatable.
I hope this is clear, otherwise tell it than I make a sample of it.

(While I am not familiar with the access find, so I hope this answer fits)

I hope this helps?

Cor

"John Hernry" <john.henry@sasktel.com>
.
> Cor,
> Thanks for the response.  I have seen your responses to these type of
[quoted text clipped - 97 lines]
>>>
>>> Greg
John Hernry - 30 Oct 2004 19:11 GMT
Cor,
So, If I understand you correctly, you are saying to create a second
dataview of the table, do my filter on it, find the record I need (which
will likely have to still be done by looping through the filtered records,
but at least far less of them), get the unique ID from the found record then
find that ID on the displayed dataview and move to that record.  Is that
about right?

John

> John,
>
[quoted text clipped - 114 lines]
>>>>
>>>> Greg
Cor Ligthert - 30 Oct 2004 19:50 GMT
John,

Seeing it again now I think that you are after this as the sample bellow?

It is very fast made, it is saterdaynight here you know

Cor

\\\
Private dtVBreg As DataTable

Private Sub Form1_Load(ByVal sender As Object, _
       ByVal e As System.EventArgs) Handles MyBase.Load
       CreateTables()
       Dim dv As New DataView(dtVBreg)
       DataGrid1.DataSource = dv
       Dim cm As CurrencyManager
       cm = CType(BindingContext(dv), CurrencyManager)
       dv.Sort = "Name,Country"
       Dim findObject(1) As Object
       findObject(0) = "Terry Burns"
       findObject(1) = "EU"
       cm.Position = dv.Find(findObject)
       DataGrid1.Select(cm.Position)
End Sub
Private Sub CreateTables()
       Dim drel As DataRelation
       dtVBreg = New DataTable("Persons")
       dtVBreg.Columns.Add("Name")
       dtVBreg.Columns.Add("Country")
       For i As Integer = 0 To 7
           dtVBreg.Rows.Add(dtVBreg.NewRow)
       Next
       dtVBreg.Rows(0).ItemArray = New Object() _
             {"Herfried K. Wagner", "EU"}
       dtVBreg.Rows(1).ItemArray = New Object() _
             {"Ken Tucker", "US"}
       dtVBreg.Rows(2).ItemArray = New Object() _
              {"CJ Taylor", "US"}
       dtVBreg.Rows(3).ItemArray = New Object() _
               {"Jay B Harlow", "US"}
       dtVBreg.Rows(4).ItemArray = New Object() _
               {"Terry Burns", "EU"}
       dtVBreg.Rows(5).ItemArray = New Object() _
               {"Tom Shelton", "US"}
       dtVBreg.Rows(6).ItemArray = New Object() _
               {"Cor Ligthert", "EU"}
   End Sub
///

"John Hernry" <john.henry@sasktel.com>
...
> Cor,
> So, If I understand you correctly, you are saying to create a second
[quoted text clipped - 126 lines]
>>>>>
>>>>> Greg
John Hernry - 30 Oct 2004 20:11 GMT
Cor,
I have done this type of find, which initiated this posting.  There are two
inherent problems.  One - No wildcard searches.  Two - Because my search
value is not unique, it does not necessarily return the first value (bug?).
This find will only find exact matches and I really am looking for wildcard
type searches without having to use a filter.

The find must also be able to perform a find next.  So I would be able to
begin my search from a specified row.

John

> John,
>
[quoted text clipped - 178 lines]
>>>>>>
>>>>>> Greg
james - 31 Oct 2004 00:25 GMT
John, go to : http://www.planetsourcecode.com/

And search for a program called: DataEasy.  It is a VB.NET program(with
source code) that will open any Access Database and allow searching
different columns(user selected) and what I like is that as you type into
the textbox it starts the search and picks all records in that field that
match what you are typing.
And it is pretty fast too.
Maybe, that will give you a couple of ideas.
james

> Cor,
> I have done this type of find, which initiated this posting.  There are
[quoted text clipped - 191 lines]
>>>>>>>
>>>>>>> Greg
Cor Ligthert - 31 Oct 2004 09:02 GMT
John,

All thougether is that what I am expecting while I sand my last message
however a newsgroup is difficult for that to communicate and this kind of
things have in my opinion to be done step by step.

My solution would be to do a search using the datarowfilter in an extra
dataview.
Than when the result is more than one,  I would let the user choose from
those in an extra datagrid. When it is one, you have it direct and with zero
there should be a message.

Than you can use the solution I gave you as last one before this with the
dataview.find with only the ID to get the exact row in the main dataview,
datagrid.

I think that this will be a good solution.
(When you do not want the selection form on your screen you can make a
showdialog form for that, remember that you have only give the dv's by value
than everything is done, because that is a reference to the used dv's)

I hope this gives some ideas?

Cor

"John Hernry" <john.henry@sasktel.com>

> Cor,
> I have done this type of find, which initiated this posting.  There are
[quoted text clipped - 191 lines]
>>>>>>>
>>>>>>> Greg
John Hernry - 31 Oct 2004 18:51 GMT
Cor and James,
Thank you for your responses.  I have taken all of your suggestions and will
be putting them into action on my project.

John

>I have been watching the dotnet newsgroups for a couple of weeks now and
>scouring the net looking for a solution to my datagrid find functionality.
[quoted text clipped - 41 lines]
>
> Greg

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.