-
Mar 3rd, 2018, 01:05 PM
#1
Thread Starter
New Member
Search in DatagridView + "search next" feature
I found the code below to do datagridview searching :
Code:
Private Function FindItems(ByVal strSearchString As String) As Boolean
dgvDisbursements.SelectionMode = DataGridViewSelectionMode.FullRowSelect
dgvDisbursements.ClearSelection()
For Each myRow As DataGridViewRow In dgvDisbursements.Rows
For Each myCell As DataGridViewCell In myRow.Cells
If InStr(myCell.Value.ToString, strSearchString) Then
myRow.Selected = True
Return True
End If
Next
Next
Return False
End Function
I need to add "Search Next" which does the searching and row selecting for all found strings in the datagridview.
-
Mar 3rd, 2018, 07:53 PM
#2
Re: Search in DatagridView + "search next" feature
If you're saying that you want to select the next matching row after the currently selected row then you should use a For loop rather than a For Each loop. That way, you can get the index of the currently selected row, increment that and use the result as the starting point for the loop.
-
Mar 4th, 2018, 08:48 AM
#3
Fanatic Member
Re: Search in DatagridView + "search next" feature
I need to add "Search Next" which does the searching and row selecting for all found strings in the datagridview.
If you're searching string matches on each row in no matter what column than use DefaultRowFilter, much better & easy. Just add Textbox for writing desired strings and create query for filter. You'll get results in grid instantly.
-
Mar 6th, 2018, 06:00 PM
#4
Thread Starter
New Member
Re: Search in DatagridView + "search next" feature
Originally Posted by jmcilhinney
If you're saying that you want to select the next matching row after the currently selected row then you should use a For loop rather than a For Each loop. That way, you can get the index of the currently selected row, increment that and use the result as the starting point for the loop.
Would you please help me with coding what u said ?
-
Mar 6th, 2018, 06:25 PM
#5
New Member
Re: Search in DatagridView + "search next" feature
Here's an example on how to accomplish that with a button and a textbox, when filtering, all applicable results related to the search will appear on the datagrid.
Code:
Private Sub FilterButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FilterButton.Click
source1.Filter = "[Item Code] = '" & TextBox1.Text & "'"
DataGridView1.Refresh()
End Sub
hope it helps.
Last edited by dday9; Mar 7th, 2018 at 09:43 AM.
-
Mar 6th, 2018, 06:32 PM
#6
Re: Search in DatagridView + "search next" feature
I did help you with coding. What I'm not doing is writing the code for you. Try to implement what I suggested and, if it doesn't work, show us what you did and tell us what it did and then we can help you fix it. I'm more than happy to help but I want to see you make an effort first. Anyone can sit back and let others write their code for them.
-
Mar 7th, 2018, 08:49 AM
#7
Thread Starter
New Member
Re: Search in DatagridView + "search next" feature
Originally Posted by jmcilhinney
I did help you with coding. What I'm not doing is writing the code for you. Try to implement what I suggested and, if it doesn't work, show us what you did and tell us what it did and then we can help you fix it. I'm more than happy to help but I want to see you make an effort first. Anyone can sit back and let others write their code for them.
Thanks for your positive intention, but If I had known to code such a thing, I would have never asked your help. I tried , but I can't even put what you suggested into a piece of code. I'm newbie
-
Mar 7th, 2018, 09:07 AM
#8
Re: Search in DatagridView + "search next" feature
Hi charlie,
how do you fill the DGV, before you start the search ?
regards
Chris
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Mar 7th, 2018, 11:00 AM
#9
Thread Starter
New Member
Re: Search in DatagridView + "search next" feature
Originally Posted by ChrisE
Hi charlie,
how do you fill the DGV, before you start the search ?
regards
Chris
DGV.Columns.Add()
DGV.Rows.Add()
-
Mar 7th, 2018, 11:33 AM
#10
Re: Search in DatagridView + "search next" feature
Originally Posted by charlie-j
DGV.Columns.Add()
DGV.Rows.Add()
well thanks for the detailed answer, now I know that the data you fill could be a coming from a Database;CSV-File;Text-File;XML-File etc...
here my detailed answer
Code:
'run to the end of the DGV rows
For i = 0 To dgv.Rows.Count - 1
'run to the end of the DGV Columns
For g = 0 To dgv.Columns.Count - 1
' your code here....
regards
Chris
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|