Set Focus On Datagrid By Using A Search Button

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 14792 Views - Last Post: 20 August 2012 - 07:33 PM Rate Topic: -----

#1 leang86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 25-May 09

Set Focus On Datagrid By Using A Search Button

Post icon  Posted 10 June 2009 - 07:17 PM

Hi, i wanna search record from my datagrid by just key in the name, then it will direct set focus on my datagrid depend the name i key. i have 1 code here, but i find that it just work on some name and just can use continues 3 times only.

Dim custName As String

custName = ""
custName = InputBox("Please Enter The Customer Name: ")
DataEnvironment1.rsBottleHdr.Find "CustName Like '" & custName & "'"
DataGrid1.SetFocus



Is it got any good idea or more suitable function can be solve my problem?
please help...........

Is This A Good Question/Topic? 0
  • +

Replies To: Set Focus On Datagrid By Using A Search Button

#2 mexlum  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-June 09

Re: Set Focus On Datagrid By Using A Search Button

Posted 10 June 2009 - 08:21 PM

Hi,

I have one piece of code that might help you. Here it is:

Dim custName As String
Dim a As Integer

custName = ""
custName = InputBox("Please Enter The Customer Name: ")


For a = 0 To DataGrid1.ApproxCount - 1
DataGrid1.Row = a
DataGrid1.Col = 3 'Number of column where the customer name is

If InStr(1, DataGrid1.Text, custName) > 0 Then
DataGrid1.SetFocus
Exit Sub
End If
Next


Let me know if this works for you.

Regards
Was This Post Helpful? 0
  • +
  • -

#3 leang86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 25-May 09

Re: Set Focus On Datagrid By Using A Search Button

Posted 10 June 2009 - 08:34 PM

View Postmexlum, on 10 Jun, 2009 - 07:21 PM, said:

Hi,

I have one piece of code that might help you. Here it is:

Dim custName As String
Dim a As Integer

custName = ""
custName = InputBox("Please Enter The Customer Name: ")


For a = 0 To DataGrid1.ApproxCount - 1
DataGrid1.Row = a
DataGrid1.Col = 3 'Number of column where the customer name is

If InStr(1, DataGrid1.Text, custName) > 0 Then
DataGrid1.SetFocus
Exit Sub
End If
Next


Let me know if this works for you.

Regards



Hi, thanks for reply my question, but got error on the code below:
DataGrid1.Row = a



The error is "Invalid Row Number".
Was This Post Helpful? 0
  • +
  • -

#4 leang86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 25-May 09

Re: Set Focus On Datagrid By Using A Search Button

Posted 10 June 2009 - 09:15 PM

View Postmexlum, on 10 Jun, 2009 - 07:21 PM, said:

Hi,

I have one piece of code that might help you. Here it is:

Dim custName As String
Dim a As Integer

custName = ""
custName = InputBox("Please Enter The Customer Name: ")


For a = 0 To DataGrid1.ApproxCount - 1
DataGrid1.Row = a
DataGrid1.Col = 3 'Number of column where the customer name is

If InStr(1, DataGrid1.Text, custName) > 0 Then
DataGrid1.SetFocus
Exit Sub
End If
Next


Let me know if this works for you.

Regards



Hi, i have try many times on your code, i find that it just able to search certain name only, and cannot continue search the next name, cause it also will jump out the same error message. Is it got any suggestion?
Thanks...
Was This Post Helpful? 0
  • +
  • -

#5 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: Set Focus On Datagrid By Using A Search Button

Posted 11 June 2009 - 07:34 PM

the only charecter you need to add your code is
*
that's all like This

Dim custName As String

custName = ""
custName = InputBox("Please Enter The Customer Name: ")
DataEnvironment1.rsBottleHdr.Find "CustName Like '" & custName & "*'"
Datagrid1.col =0
DataGrid1.SetFocus




Was This Post Helpful? 0
  • +
  • -

#6 leang86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 25-May 09

Re: Set Focus On Datagrid By Using A Search Button

Posted 12 June 2009 - 12:25 AM

View Postthava, on 11 Jun, 2009 - 06:34 PM, said:

the only charecter you need to add your code is
*
that's all like This

Dim custName As String

custName = ""
custName = InputBox("Please Enter The Customer Name: ")
DataEnvironment1.rsBottleHdr.Find "CustName Like '" & custName & "*'"
Datagrid1.col =0
DataGrid1.SetFocus






Thanks for reply, still got a lot name cannot be search, but i can feel that have a big changes by using your suggestion, cause got many name that cannot be search normally, able be search already. anywhere, Thanks....
Was This Post Helpful? 0
  • +
  • -

#7 leang86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 25-May 09

Re: Set Focus On Datagrid By Using A Search Button

Posted 22 June 2009 - 09:47 PM

View Postmexlum, on 10 Jun, 2009 - 07:21 PM, said:

Hi,

I have one piece of code that might help you. Here it is:

Dim custName As String
Dim a As Integer

custName = ""
custName = InputBox("Please Enter The Customer Name: ")


For a = 0 To DataGrid1.ApproxCount - 1
DataGrid1.Row = a
DataGrid1.Col = 3 'Number of column where the customer name is

If InStr(1, DataGrid1.Text, custName) > 0 Then
DataGrid1.SetFocus
Exit Sub
End If
Next


Let me know if this works for you.

Regards



Hi, now i was using this code:
Private Sub cmdSearch_Click()
Dim custName As String
Dim a As Integer

custName = InputBox("Please Key In The Customer Name")
If custName = "" Then
  MsgBox ("Record Not Found")
  Exit Sub
Else
For a = 0 To DataGrid1.ApproxCount - 1
  DataGrid1.Row = a
  DataGrid1.Col = 0
  If InStr(1, DataGrid1.Text, custName) > 0 Then
	DataGrid1.SetFocus
	Exit Sub
  Else
  On Error GoTo error_handler
  End If
Next
End If

error_handler:
MsgBox ("Rocord No Found")
Exit Sub
End Sub



But it just can search the data where the datagrid showing, that mean if i have 20 row data in my datagrid, and my datagrid just can show 10 row per scroll. When i scroll to the first 10 row, and i search the name that showing in the first 10 row, it able to search, but if i search the name that did'nt show in the first 10 row or maybe in the 11 row on my datagrid, it unable to set focus, and it assume record no found.
Please help me....
Thanks....

This post has been edited by leang86: 22 June 2009 - 09:48 PM

Was This Post Helpful? 0
  • +
  • -

#8 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Set Focus On Datagrid By Using A Search Button

Posted 23 June 2009 - 01:58 AM

then select the row from datagrid that is found that way he will be in visible range :) then no record no found like so

Private Sub cmdSearch_Click()
Dim custName As String
Dim a As Integer

custName = InputBox("Please Key In The Customer Name")
If custName = "" Then
  MsgBox ("Record Not Found")
  Exit Sub
Else
For a = 0 To DataGrid1.ApproxCount - 1
  DataGrid1.Row = a
  DataGrid1.Col = 0
  If InStr(1, DataGrid1.Text, custName) > 0 Then
	DataGrid1.CellSelected(a,0)=True
	DataGrid1.SetFocus
	Exit Sub
  Else
  On Error GoTo error_handler
  End If
Next
End If

error_handler:
MsgBox ("Rocord No Found")
Exit Sub
End Sub



i hope this will work for you :)

This post has been edited by NoBrain: 23 June 2009 - 02:02 AM

Was This Post Helpful? 0
  • +
  • -

#9 leang86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 25-May 09

Re: Set Focus On Datagrid By Using A Search Button

Posted 23 June 2009 - 08:35 PM

View PostNoBrain, on 23 Jun, 2009 - 12:58 AM, said:

then select the row from datagrid that is found that way he will be in visible range :) then no record no found like so

Private Sub cmdSearch_Click()
Dim custName As String
Dim a As Integer

custName = InputBox("Please Key In The Customer Name")
If custName = "" Then
  MsgBox ("Record Not Found")
  Exit Sub
Else
For a = 0 To DataGrid1.ApproxCount - 1
  DataGrid1.Row = a
  DataGrid1.Col = 0
  If InStr(1, DataGrid1.Text, custName) > 0 Then
	DataGrid1.CellSelected(a,0)=True
	DataGrid1.SetFocus
	Exit Sub
  Else
  On Error GoTo error_handler
  End If
Next
End If

error_handler:
MsgBox ("Rocord No Found")
Exit Sub
End Sub



i hope this will work for you :)



Hi, Thanks for reply, i found that there have an error on the code:
	DataGrid1.CellSelected(a,0)=True



The Error message are:
Method or data member not found

And i found that i dun have "CellSelected" function in my datagrid, why?
Please Help Me......
Was This Post Helpful? 0
  • +
  • -

#10 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Set Focus On Datagrid By Using A Search Button

Posted 23 June 2009 - 11:47 PM

well look this
Property CellSelected(lRow As Long, lCol As Long) As Boolean
Member of vbAcceleratorSGrid6.vbalGrid
Gets/sets whether a cell is selected or not.

now look if vbAccelerator VB6 SGrid Control 2.0 is selected in your components it is c:\WINDOWS\System32\vbalsgrid6.ocx

now that is what i think it is i hope i will help you

This post has been edited by NoBrain: 23 June 2009 - 11:49 PM

Was This Post Helpful? 0
  • +
  • -

#11 leang86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 25-May 09

Re: Set Focus On Datagrid By Using A Search Button

Posted 24 June 2009 - 12:35 AM

View PostNoBrain, on 23 Jun, 2009 - 10:47 PM, said:

well look this
Property CellSelected(lRow As Long, lCol As Long) As Boolean
Member of vbAcceleratorSGrid6.vbalGrid
Gets/sets whether a cell is selected or not.

now look if vbAccelerator VB6 SGrid Control 2.0 is selected in your components it is c:\WINDOWS\System32\vbalsgrid6.ocx

now that is what i think it is i hope i will help you



Hi, Thanks for reply.
Just now i have download vbalsgrid6.ocx to my System32, and inserted to component list, but the same problem still happen. Is it i need to change to using the vbalgrid? What I need to do???
Was This Post Helpful? 0
  • +
  • -

#12 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Set Focus On Datagrid By Using A Search Button

Posted 24 June 2009 - 01:37 AM

well i gues you must just change the grid if your using the old one just delete and replace it with vbalgrid and put the same name i gues you will not have much problems replacing it :) btw what ocx your using for grid

This post has been edited by NoBrain: 24 June 2009 - 01:38 AM

Was This Post Helpful? 0
  • +
  • -

#13 leang86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 25-May 09

Re: Set Focus On Datagrid By Using A Search Button

Posted 24 June 2009 - 01:39 AM

View PostNoBrain, on 24 Jun, 2009 - 12:37 AM, said:

well i gues you must just change the grid if your using the old one just delete and replace it with vbalgrid and put the same name i gues you will not have much problems replacing it :)


But i have receive a error when i add the vbalgrid to my form, the error are:
Run Time Error '0'
What's the problem?
Was This Post Helpful? 0
  • +
  • -

#14 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Set Focus On Datagrid By Using A Search Button

Posted 24 June 2009 - 01:41 AM

hmmm that is interesting your using 6.0 and that is when you add the component or when you want to draw the table ?
Was This Post Helpful? 0
  • +
  • -

#15 leang86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 25-May 09

Re: Set Focus On Datagrid By Using A Search Button

Posted 24 June 2009 - 06:27 PM

View PostNoBrain, on 24 Jun, 2009 - 12:41 AM, said:

hmmm that is interesting your using 6.0 and that is when you add the component or when you want to draw the table ?



Ya, I'm using vb6.0, and i was able to add the vbAccelerator vb6 SGrid Control 2.0 to my component list, but when i draw the table, it jump out the error message, and not allow me to continue, is it my .dll or .sys file of this component got problem? Cause i just download it from internet, or can you send me the require file to my email? My email: leang86@hotmail.com

Thanks for reply
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2