Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 448

How to get the rowindex by searching text from datagridview on vbnet

$
0
0

I am stuck on a simple thing. My app has a datagridview with 3 columns. One columnshave the name "Sites" and I have added the rows to it as in: sites1, site2, etc.

What I want is for it to give me the simple function code to get the rowindex by searching the name of the site, like site1, from the "Sites" column.

I am messing with the below function but failed. Does you can please modified below function for me. So by this I will be able to get the rowindex by searching site value like site1, site2 etc.

Function FindValue(ByRef dgv As DataGridView, ByVal metric_key As Object) As DataGridViewRowFor Each row As DataGridViewRow In dgv.Rows    If row.Cells.Item("metric_value").Value = metric_key Then        Return row    End IfNextReturn Nothing

End Function

Usage of functiondataGridView1.FindValue(1)

Finally I found the way by my self to find the rowindex by value

Here is mine code

Dim rowindex As StringFor Each row As DataGridViewRow In DataGridView1.Rows  If row.Cells.Item("yourcolumnnamehere").Value = "valueforwhichyouaresearching" Then    rowindex = row.Index.ToString()    MsgBox(rowindex)

Viewing all articles
Browse latest Browse all 448

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>