Rowel Virgo
asked on
Display the items searched in DatagridView (Textbox, Button and Datagridview)
Hi,
I'm using Visual Studio Community 2017. In my case, I have text box named: txtSEARCH, Button named: cmdSEARCH and a Datagridview named: DataGridView1.
Datagridview populated from a text file named: "D:\esdcheck\.BAK.dll" and manualy put column in properties.
and this is my DataGridView (This is my form)
What I want to do is to search User ID and display it in DataGridView
ex:
I type "1504579" in the text box (txtSEARCH) and when I click the button, datagridview will display all "1504579" in the list 'ONLY' from Rowel Virgo
I'm searching all day in the internet but no codes for like that, any help please and Thank you
This is How I populate my DatagridView:
this is my first post Listview and Datagridview and thank you for the reply sir
I'm using Visual Studio Community 2017. In my case, I have text box named: txtSEARCH, Button named: cmdSEARCH and a Datagridview named: DataGridView1.
Datagridview populated from a text file named: "D:\esdcheck\.BAK.dll" and manualy put column in properties.
and this is my DataGridView (This is my form)
What I want to do is to search User ID and display it in DataGridView
ex:
I type "1504579" in the text box (txtSEARCH) and when I click the button, datagridview will display all "1504579" in the list 'ONLY' from Rowel Virgo
I'm searching all day in the internet but no codes for like that, any help please and Thank you
This is How I populate my DatagridView:
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim lines = (From line In IO.File.ReadAllLines("D:esdcheck\BAK.dll")
Select line.Split(CChar(","c))).ToArray
For x As Integer = 0 To lines.GetUpperBound(0)
DataGridView1.Rows.Add(lines(x))
Next
End Sub
End Class
this is my first post Listview and Datagridview and thank you for the reply sir
Scott McDaniel (Microsoft Access MVP - EE MVE )Account
Ryan ChongAccount
ASKER
Yey! I got the code BUT!
when I click the cmdSEARCH button, it display this error, any one please help
error:
I got the code here:
Search Inside Datagridview Winforms VB.NET
when I click the cmdSEARCH button, it display this error, any one please help
error:
System.Windows.Forms.DataGridViewCel l.Value.ge t returned Nothing.
I got the code here:
Search Inside Datagridview Winforms VB.NET
Private Sub cmdSEARCH_Click(sender As Object, e As EventArgs) Handles cmdSEARCH.Click
If txtSEARCH.Text <> "" Then
Dim s As String = txtSEARCH.Text.Trim
DataGridView1.ClearSelection()
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
Dim someText As String = s
Dim gridRow As Integer = 0
Dim gridColumn As Integer = 0
For Each Row As DataGridViewRow In DataGridView1.Rows
For Each column As DataGridViewColumn In DataGridView1.Columns
Dim cell As DataGridViewCell = (DataGridView1.Rows(gridRow).Cells(gridColumn))
If cell.Value.ToString.ToLower.Contains(someText.ToLower) Then
'cell.Style.BackColor = Color.Yellow
DataGridView1.FirstDisplayedScrollingRowIndex = Row.Index
DataGridView1.Item(cell.ColumnIndex, cell.RowIndex).Selected = True
End If
gridColumn += 1
Next column
gridColumn = 0
gridRow += 1
Next Row
Else
DataGridView1.ClearSelection()
End If
End Sub
Sorry.JPG
ASKER
@Repost
I put the code in Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
but it only highlights the rows with the same text i inputed, how to display only the text I searched?
I searched for Names but this happend:
I searched for User ID but this happened:
I put the code in Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
but it only highlights the rows with the same text i inputed, how to display only the text I searched?
I searched for Names but this happend:
I searched for User ID but this happened:
DataGridView1.Item(cell.ColumnIndex, cell.RowIndex).Selected = True
dont use this
set rowselection of grid to false, and only select cells...
ASKER
From HainKurt Reply
I can't sort the searched character
I can't sort the searched character
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks sir
like
"[UserName] + [User ID] + [Department] like '*" & mySearchText & "*'"
or
"[UserName] + [User ID] + [Department] like '%" & mySearchText & "%'"
just a few lines of code, and you should be ok...
then set filter to "" to show all rows again...