Click here to Skip to main content
15,887,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi guy's
i used this code :
C#
private void textBox1_TextChanged(object sender, EventArgs e)
        {
        //    DataGridViewRow row2 =
        //(from DataGridViewRow r in dataGridView1.Rows
        // where r.Cells["InvoiceId"].Value.ToString().Equals(textBox1.Text)
        // select r).FirstOrDefault();
        //    if (row2 != null)
        //    row2.Selected = true;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (row.Cells["InvoiceId"].Value == null)
                {
                    continue;
                }
                if (row.Cells["InvoiceId"].Value.ToString().Trim() == textBox1.Text)
                {
                    dataGridView1.CurrentCell = row.Cells["InvoiceId"];
                    dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows[row.Index].Index;
                    return;
                }
            }
        }


to search in datagridview to find and select row ! (no filter)
butt, when datagrid have Repetitive value in row's ---> ERROR !
How do I put a button to the next row with every click to Btn_find ?
(Find similar Excel)

thanks
Posted
Comments
CHill60 6-May-15 7:55am    
What is the error?
MayurDighe 6-May-15 14:34pm    
Don't Answer your Own Question.

This community is to get answers from others for any programming.

And...NOT to Anwser own question like this one you have done.
MayurDighe 6-May-15 14:38pm    
Make a new question or improvise the existing question if you got the partial solution for your problem statement.
ghasem110deh 6-May-15 16:13pm    
A small error but still has not been fixed.
Well you answer :(
How do I find the next row by clicking on the button?

1 solution

error be OK !
how find next row :

C#
private void button1_Click(object sender, EventArgs e)
        {
            button1.Text = "Find Next";
            {
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (row.Cells["ProductId"].Value == null)
                    {
                        continue;
                    }
                    if (row.Cells["ProductId"].Value.ToString().Trim() == textBox1.Text)
                    {
                        dataGridView1.CurrentCell = row.Cells["ProductId"];
                        dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows[row.Index].Index;
                        return;
                    }
                }
            }
        }
 
Share this answer
 
Comments
ghasem110deh 6-May-15 16:23pm    
i want like Excel search and find the next row, the amount is equal
where button clicked !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900