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)









share|improve this question




















  • 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















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)









share|improve this question




















  • 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













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)









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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












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





share|improve this answer





















  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























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





share|improve this answer





















  • 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















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





share|improve this answer





















  • 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













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





share|improve this answer












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






share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?