How to get the rowindex by searching text from datagridview on vbnet
up vote
2
down vote
favorite
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 DataGridViewRow
For Each row As DataGridViewRow In dgv.Rows
If row.Cells.Item("metric_value").Value = metric_key Then
Return row
End If
Next
Return Nothing
End Function
Usage of function
dataGridView1.FindValue(1)
Finally I found the way by my self to find the rowindex by value
Here is mine code
Dim rowindex As String
For Each row As DataGridViewRow In DataGridView1.Rows
If row.Cells.Item("yourcolumnnamehere").Value = "valueforwhichyouaresearching" Then
rowindex = row.Index.ToString()
MsgBox(rowindex)
vb.net datagridview rows
add a comment |
up vote
2
down vote
favorite
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 DataGridViewRow
For Each row As DataGridViewRow In dgv.Rows
If row.Cells.Item("metric_value").Value = metric_key Then
Return row
End If
Next
Return Nothing
End Function
Usage of function
dataGridView1.FindValue(1)
Finally I found the way by my self to find the rowindex by value
Here is mine code
Dim rowindex As String
For Each row As DataGridViewRow In DataGridView1.Rows
If row.Cells.Item("yourcolumnnamehere").Value = "valueforwhichyouaresearching" Then
rowindex = row.Index.ToString()
MsgBox(rowindex)
vb.net datagridview rows
1
SO is not really the place to say "give it to me". We generally prefer to hear "I've tried X and X_q1 doesn't work. Can you help?". Citing inexperience is not an excuse to not try, so, what have you tried?
– DACrosby
Jul 5 '13 at 20:58
1
I was tried many functions and lots of codes. I waste my about 4 hours for trying this but cant get any result. One of the method which I was tried is TextBox1.Text = "" Dim FirstValue As Boolean = True Dim cell As DataGridViewCell For Each cell In DataGridView1.SelectedCells If Not FirstValue Then TextBox1.Text += ", " End If TextBox1.Text += cell.Value.ToString() FirstValue = False Next
– wahab wahab1
Jul 5 '13 at 23:04
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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 DataGridViewRow
For Each row As DataGridViewRow In dgv.Rows
If row.Cells.Item("metric_value").Value = metric_key Then
Return row
End If
Next
Return Nothing
End Function
Usage of function
dataGridView1.FindValue(1)
Finally I found the way by my self to find the rowindex by value
Here is mine code
Dim rowindex As String
For Each row As DataGridViewRow In DataGridView1.Rows
If row.Cells.Item("yourcolumnnamehere").Value = "valueforwhichyouaresearching" Then
rowindex = row.Index.ToString()
MsgBox(rowindex)
vb.net datagridview rows
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 DataGridViewRow
For Each row As DataGridViewRow In dgv.Rows
If row.Cells.Item("metric_value").Value = metric_key Then
Return row
End If
Next
Return Nothing
End Function
Usage of function
dataGridView1.FindValue(1)
Finally I found the way by my self to find the rowindex by value
Here is mine code
Dim rowindex As String
For Each row As DataGridViewRow In DataGridView1.Rows
If row.Cells.Item("yourcolumnnamehere").Value = "valueforwhichyouaresearching" Then
rowindex = row.Index.ToString()
MsgBox(rowindex)
vb.net datagridview rows
vb.net datagridview rows
edited Jul 7 '13 at 23:38
matzone
5,22731016
5,22731016
asked Jul 5 '13 at 20:36
wahab wahab1
13115
13115
1
SO is not really the place to say "give it to me". We generally prefer to hear "I've tried X and X_q1 doesn't work. Can you help?". Citing inexperience is not an excuse to not try, so, what have you tried?
– DACrosby
Jul 5 '13 at 20:58
1
I was tried many functions and lots of codes. I waste my about 4 hours for trying this but cant get any result. One of the method which I was tried is TextBox1.Text = "" Dim FirstValue As Boolean = True Dim cell As DataGridViewCell For Each cell In DataGridView1.SelectedCells If Not FirstValue Then TextBox1.Text += ", " End If TextBox1.Text += cell.Value.ToString() FirstValue = False Next
– wahab wahab1
Jul 5 '13 at 23:04
add a comment |
1
SO is not really the place to say "give it to me". We generally prefer to hear "I've tried X and X_q1 doesn't work. Can you help?". Citing inexperience is not an excuse to not try, so, what have you tried?
– DACrosby
Jul 5 '13 at 20:58
1
I was tried many functions and lots of codes. I waste my about 4 hours for trying this but cant get any result. One of the method which I was tried is TextBox1.Text = "" Dim FirstValue As Boolean = True Dim cell As DataGridViewCell For Each cell In DataGridView1.SelectedCells If Not FirstValue Then TextBox1.Text += ", " End If TextBox1.Text += cell.Value.ToString() FirstValue = False Next
– wahab wahab1
Jul 5 '13 at 23:04
1
1
SO is not really the place to say "give it to me". We generally prefer to hear "I've tried X and X_q1 doesn't work. Can you help?". Citing inexperience is not an excuse to not try, so, what have you tried?
– DACrosby
Jul 5 '13 at 20:58
SO is not really the place to say "give it to me". We generally prefer to hear "I've tried X and X_q1 doesn't work. Can you help?". Citing inexperience is not an excuse to not try, so, what have you tried?
– DACrosby
Jul 5 '13 at 20:58
1
1
I was tried many functions and lots of codes. I waste my about 4 hours for trying this but cant get any result. One of the method which I was tried is TextBox1.Text = "" Dim FirstValue As Boolean = True Dim cell As DataGridViewCell For Each cell In DataGridView1.SelectedCells If Not FirstValue Then TextBox1.Text += ", " End If TextBox1.Text += cell.Value.ToString() FirstValue = False Next
– wahab wahab1
Jul 5 '13 at 23:04
I was tried many functions and lots of codes. I waste my about 4 hours for trying this but cant get any result. One of the method which I was tried is TextBox1.Text = "" Dim FirstValue As Boolean = True Dim cell As DataGridViewCell For Each cell In DataGridView1.SelectedCells If Not FirstValue Then TextBox1.Text += ", " End If TextBox1.Text += cell.Value.ToString() FirstValue = False Next
– wahab wahab1
Jul 5 '13 at 23:04
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Maybe you mean ...
For Each cell In DataGridView1.SelectedCells
If Not FirstValue Then
TextBox1.Text += cell.Value.ToString() & ", "
Else
TextBox1.Text += cell.Value.ToString()
FirstValue= False
End If
Next
Thanks for the reply but its not working. I want to get the rowindex by searching value. Like the first column is of the sites and its contains many rows of sites. Like row 1 google.com, row 2 yahoo.com. So I want to find the rowindex by searching the value like "google.com" or "yahoo.com". I have found a stackoverflow.com/questions/4228278/… , where somebody have replied to how to find rowindex by value. But it have 2 columns. Please see that url and you can easily modified it for me. Again very thanks!
– wahab wahab1
Jul 7 '13 at 17:24
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Maybe you mean ...
For Each cell In DataGridView1.SelectedCells
If Not FirstValue Then
TextBox1.Text += cell.Value.ToString() & ", "
Else
TextBox1.Text += cell.Value.ToString()
FirstValue= False
End If
Next
Thanks for the reply but its not working. I want to get the rowindex by searching value. Like the first column is of the sites and its contains many rows of sites. Like row 1 google.com, row 2 yahoo.com. So I want to find the rowindex by searching the value like "google.com" or "yahoo.com". I have found a stackoverflow.com/questions/4228278/… , where somebody have replied to how to find rowindex by value. But it have 2 columns. Please see that url and you can easily modified it for me. Again very thanks!
– wahab wahab1
Jul 7 '13 at 17:24
add a comment |
up vote
0
down vote
Maybe you mean ...
For Each cell In DataGridView1.SelectedCells
If Not FirstValue Then
TextBox1.Text += cell.Value.ToString() & ", "
Else
TextBox1.Text += cell.Value.ToString()
FirstValue= False
End If
Next
Thanks for the reply but its not working. I want to get the rowindex by searching value. Like the first column is of the sites and its contains many rows of sites. Like row 1 google.com, row 2 yahoo.com. So I want to find the rowindex by searching the value like "google.com" or "yahoo.com". I have found a stackoverflow.com/questions/4228278/… , where somebody have replied to how to find rowindex by value. But it have 2 columns. Please see that url and you can easily modified it for me. Again very thanks!
– wahab wahab1
Jul 7 '13 at 17:24
add a comment |
up vote
0
down vote
up vote
0
down vote
Maybe you mean ...
For Each cell In DataGridView1.SelectedCells
If Not FirstValue Then
TextBox1.Text += cell.Value.ToString() & ", "
Else
TextBox1.Text += cell.Value.ToString()
FirstValue= False
End If
Next
Maybe you mean ...
For Each cell In DataGridView1.SelectedCells
If Not FirstValue Then
TextBox1.Text += cell.Value.ToString() & ", "
Else
TextBox1.Text += cell.Value.ToString()
FirstValue= False
End If
Next
answered Jul 6 '13 at 1:11
matzone
5,22731016
5,22731016
Thanks for the reply but its not working. I want to get the rowindex by searching value. Like the first column is of the sites and its contains many rows of sites. Like row 1 google.com, row 2 yahoo.com. So I want to find the rowindex by searching the value like "google.com" or "yahoo.com". I have found a stackoverflow.com/questions/4228278/… , where somebody have replied to how to find rowindex by value. But it have 2 columns. Please see that url and you can easily modified it for me. Again very thanks!
– wahab wahab1
Jul 7 '13 at 17:24
add a comment |
Thanks for the reply but its not working. I want to get the rowindex by searching value. Like the first column is of the sites and its contains many rows of sites. Like row 1 google.com, row 2 yahoo.com. So I want to find the rowindex by searching the value like "google.com" or "yahoo.com". I have found a stackoverflow.com/questions/4228278/… , where somebody have replied to how to find rowindex by value. But it have 2 columns. Please see that url and you can easily modified it for me. Again very thanks!
– wahab wahab1
Jul 7 '13 at 17:24
Thanks for the reply but its not working. I want to get the rowindex by searching value. Like the first column is of the sites and its contains many rows of sites. Like row 1 google.com, row 2 yahoo.com. So I want to find the rowindex by searching the value like "google.com" or "yahoo.com". I have found a stackoverflow.com/questions/4228278/… , where somebody have replied to how to find rowindex by value. But it have 2 columns. Please see that url and you can easily modified it for me. Again very thanks!
– wahab wahab1
Jul 7 '13 at 17:24
Thanks for the reply but its not working. I want to get the rowindex by searching value. Like the first column is of the sites and its contains many rows of sites. Like row 1 google.com, row 2 yahoo.com. So I want to find the rowindex by searching the value like "google.com" or "yahoo.com". I have found a stackoverflow.com/questions/4228278/… , where somebody have replied to how to find rowindex by value. But it have 2 columns. Please see that url and you can easily modified it for me. Again very thanks!
– wahab wahab1
Jul 7 '13 at 17:24
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f17496523%2fhow-to-get-the-rowindex-by-searching-text-from-datagridview-on-vbnet%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
SO is not really the place to say "give it to me". We generally prefer to hear "I've tried X and X_q1 doesn't work. Can you help?". Citing inexperience is not an excuse to not try, so, what have you tried?
– DACrosby
Jul 5 '13 at 20:58
1
I was tried many functions and lots of codes. I waste my about 4 hours for trying this but cant get any result. One of the method which I was tried is TextBox1.Text = "" Dim FirstValue As Boolean = True Dim cell As DataGridViewCell For Each cell In DataGridView1.SelectedCells If Not FirstValue Then TextBox1.Text += ", " End If TextBox1.Text += cell.Value.ToString() FirstValue = False Next
– wahab wahab1
Jul 5 '13 at 23:04