-4

I have problem with textbox finding I have got this piece of program to make "Starts With" method to find it by putting three letters into the textbox and it will find all that matches with three starting letters. Here is the code I have used

    private void findTextBox_TextChanged(object sender, EventArgs e)
    {
        var bd = (BindingSource)debtDGV.DataSource;
        var dt = (DataTable)bd.DataSource;
        dt.DefaultView.RowFilter = string.Format(" '{0}%'", findTextBox.Text.Trim().Replace("'", "''"));
        debtDGV.Refresh();
    }
Kaeron
  • 3
  • 3
  • What is null? Have you attached debugger? Put a breakpoint on the first line of the method and debug it. Go line by line in the debugger and see which thing is null. – Stuart May 25 '17 at 12:26

1 Answers1

0

You can use this code to check rows one by one and check if textbox value contains value of cells

                foreach (DataGridViewCell oneCell in dataGridView1.SelectedCells)
                {
                    string data = (string)dataGridView1[0, a].Value; //0 is column index here
                    if (data.StartsWith(textBox1.Text)) // You can use Contains instead of StartsWith to search all the value
                    {
                        //What happens when You find the specified cell
                    }
                }

You can use another loop for checking into all cells if you want. this code is just for cells of first column

Taha -A-
  • 84
  • 1
  • 7