Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to clear grid before doing a search?

Status
Not open for further replies.

croiva25

Technical User
Dec 3, 2003
125
0
0
AU
I have a screen which is a submitting screen and a search screen at the same time and result of the search gets dispalyed in a grid.That is fine,but if I search for records (example starting with "ac")that will give me a list of records that contain those letters,that is fine.

What i have a problem with is that I clear the field criteria and start a new search but it only gets added onto what I have displayed in the grid so some records end up being dispalyed again even though they only exist once.

So when I clear the field where I enter the search criteria i would like to clear the grid as well, not having all that luck with that.

this is the code for search button,use SQLserver as a database:
Private Sub cmdSearch_Click()
Dim szQuery As String
Dim ctrlObj As Control
Dim szTemp As String
Dim nErr As Integer
Dim Handle As Integer
Dim lCount As Long
Dim szDate As String
Dim szDate1 As String

lstResults.ListItems.Clear

Handle = SessionHandle(cszSessionHandle)
If Handle < 0 Then
Call myobj.ReportError(Handle, Handle, "connecting to the required database.", App.title)
Exit Sub
End If

For Each ctrlObj In Controls
If ctrlObj.Tag <> "" Then
Select Case Left$(ctrlObj.Name, 3)
Case "txt"
If ctrlObj.Text <> "" Then
If szQuery <> "" Then
szQuery = szQuery & " AND DispatchTime IS NULL "
End If
szQuery = szQuery & Replace(ctrlObj.Tag, "%", BuildString(ctrlObj.Text, , WILD_BOTH))
End If
End Select
End If
Next

If szQuery <> "" Then
szQuery = " WHERE " & szQuery & " AND DispatchTime IS NULL"
End If

MousePointer = 11

nErr = myobj.DoQuery(Handle, "TEST", szQuery)
If myobj.ReportError(Handle, nErr, "searching the Customer details.", App.title) = True Then
MousePointer = 0
Exit Sub
End If

grdResults.Visible = False

For lCount = 0 To myobj.ListCount(Handle) - 1
szDate = myobj.List(Handle, lCount, "PrintedWhen")
If IsDate(szDate) Then
szDate = StandardDateTime(CDate(szDate))
End If
grdResults.AddItem myobj.List(Handle, lCount, "FirstBoxNbr") & vbTab & _
szDate & vbTab & _
myobj.List(Handle, lCount, "DispatchTime")
Next lCount

fraDispatchResults.Caption = "Units to be dispatched (" & CStr(grdResults.Rows - 1) & ")"
grdResults.Visible = True

grdResults.Visible = True
MousePointer = 0

End Sub


This is the clear button code:

Private Sub cmdClear_Click()
Dim ctrlObj As Control

For Each ctrlObj In Controls
If ctrlObj.Tag <> "" Then
Select Case Left$(ctrlObj.Name, 3)
Case "txt"
ctrlObj.Text = ""
End Select
End If
Next
End Sub


So how could I clear the grid, either with the clear button or to clear it when I start a new search.

Could somebody please help me with this?

regards
 

who's/what grid control are you using - MSFlexGrid?

Two options:

1. grdResults.Clear - will just blank out all the rows

2. this will actually delete the rows from the grid (better if you want to use AddItem to repopulate).

Dim l As Long

For l = grdResults.Rows - 1 To 1 Step -1
grdResults.RemoveItem l
Next l
 
thanks for your reply, yes grdResults.clear will blank out all the rows visibly, text only, the rows are still there but empty, and new search is still getting added onto the cleared rows,so that is no good for my case.

MSFlexGrid

the second option works, thanks,I have access to a lot of code from my Senior programmer but consider myselft a beginner, so thanks for your help


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top