Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Here is VB code for Incremental Search Grid
Message
 
To
13/07/2004 10:27:46
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
00923715
Message ID:
00923838
Views:
21
Hi Tony can you add this to the downloads area. If you don't have PUTM you can't search the archives so a lot of memebers won't be able to get access to your code.

If it is in the downloads area, regular members can download it as well.

Thanks for the code....
:-)

Shawn


>Here it is: Code for an Incremental Search Grid in VB .NET
>
>I got so frustrated trying to find an Incremental Search Grid in VB .NET that it drove me to finally write the code myself. I got a hint of how to do it from Kenvin Goff here in the Universal Thread Mere Mortals section, but it was in C, and I'm a VB programmer; but I finally figured it out, and I finally got to do it in VB .NET. I'm not a real experienced VB .NET programmer so there may be a lot of redundant code in here, and I might not know completely what I'm talking about, but the thing does work.
>
>First I have a tab screen (Find Records) that has some labels, text boxes, buttons and a grid on it. Here are the important ones:
>txtReqNum2, txtPO_Num, txtCompany
>grdReqs bound to Requisitions business object.
>
>I use stored procedures to get the records, and only for the currently logged in user.
>
>Here's the code:
>----------------------------------------------------------------------------
> Private Sub txtReqNum2_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtReqNum2.GotFocus
> Me.dsReqs = Me.oRequisitions.GetReqsForUserSP(gcUser)
> ClearControls()
> End Sub
>
> Private Sub txtPO_Num_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPO_Num.GotFocus
> Me.dsReqs = Me.oRequisitions.GetReqsForUserPOSortSP(gcUser)
> ClearControls()
> End Sub
>
> Private Sub txtCompany_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCompany.GotFocus
> Me.dsReqs = Me.oRequisitions.GetReqsForUserCompSortSP(gcUser)
> ClearControls()
> End Sub
>
> Private Sub txtReqNum2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtReqNum2.TextChanged
> Dim lcStr As String
> lcStr = UCase(Trim(Me.txtReqNum2.Text().ToString))
> IncrSearch(lcStr, "ReqID")
> End Sub
>
> Private Sub txtPO_Num_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPO_Num.TextChanged
> Dim lcStr As String
> lcStr = UCase(Trim(Me.txtPO_Num.Text().ToString))
> IncrSearch(lcStr, "PONum")
> End Sub
>
> Private Sub txtCompany_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCompany.TextChanged
> Dim lcStr As String
> lcStr = UCase(Trim(Me.txtCompany.Text().ToString))
> IncrSearch(lcStr, "Company")
> End Sub
>
> Private Sub IncrSearch(ByVal lcStr, ByVal lcSortOrder)
> 'Get the Default View of the DataSet
> Dim ds As DataSet = Me.oRequisitions.GetCurrentDataSet()
> ds.Tables(0).DefaultView.Sort = lcSortOrder
>
> 'Set up the local search variables
> Dim i, lnRowCount, lnSize As Integer
> Dim lcField, lcSrchTerm, lcReqID As String
> Dim bMgr = Me.BindingContext(grdReqs.DataSource, grdReqs.DataMember)
> lnRowCount = Me.oRequisitions.GetRowCount
> lnSize = Len(lcStr)
>
> 'Start searching for the lcField value
> For i = 0 To lnRowCount - 1
> 'Get the field value for the row
> lcField = UCase(ds.Tables(0).DefaultView(i)(lcSortOrder))
> lcSrchTerm = Microsoft.VisualBasic.Left(lcField, lnSize)
> If lcSrchTerm = lcStr Then
> Dim Position As Integer = ds.Tables(0).DefaultView.Find(lcField)
> Me.BindingContext(dsReqs, dsReqs.Tables(0).TableName).Position = Position
> bMgr.position = Position
> Exit For
> End If
> Next
>
> End Sub
>
> Private Sub ClearControls()
> Me.txtReqNum2.Text = ""
> Me.txtPO_Num.Text = ""
> Me.txtCompany.Text = ""
> End Sub
>
>----------------------------------------------------------------------------
>Here's the way it works:
>When a text box gets the focus it sets the sort of the data set so that the grid column is displayed in the correct sort order, and then clears out the text boxes:
>
> Me.dsReqs = Me.oRequisitions.GetReqsForUserCompSortSP(gcUser)
> ClearControls()
>
>Then when the text changes, it formats the search string and calls the IncrSearch function with the search string and to set the sort order for the search.
>
> Dim lcStr As String
> lcStr = UCase(Trim(Me.txtCompany.Text().ToString))
> IncrSearch(lcStr, "Company")
>
>The incremental search function then makes sure the Default View is in the correct sort order. It then sets up the local search variables and binds the grid to the data set.
>
>It then looks through the records, first to get the actual field value, then for the first letter of the search string we are looking for, and if it finds a match, will get it's position, makes sure the grid is pointing to it, and then jumps out of the loop, ready to get the next letter. (Warning, this code doesn't like Nulls in the fields, so for now I just make sure there isn't any in my tables.)
>
>That's it. I hope this will help you all out.
>
>CU
Shawn Dorion
Geo Sektor Dot Com
Website: http://www.geosektor.com

Web Hosting Plans
Visit : http://WebHosting.Applications4u.com/
Previous
Reply
Map
View

Click here to load this message in the networking platform