SomethingStrange
SomethingStrange

Reputation: 121

Insert Space After (x) characters in a string pulled from DataGridView

I've imported a CSV file and am populating a DataGridView. One of the columns has a set of numbers from the CSV that all have spaces in the numbers, I'm trying to allow a user to search that field but the spaces are causing issues.

I've been able to target the specific column but I don't know how to allow a user to search and omit those spaces.

           if (numberradioButton.Checked == true)
        {

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (row.Cells[11].Value.ToString().Equals(textBox1.Text))
                {
                    row.Visible = true;
                    row.Cells[11].Style.ForeColor = Color.Red;
                }
                else
                {
                    row.Visible = false;
                }
            }

The numbers are always in the format of XX XXXXXX XXXXXX X. The string that the user will type into the textbox is XXXXXXXXXXXXXXX. My thinking is that I'll have to parse what the user enters and insert a space in the correct places. Any help would be greatly appreciated.

Upvotes: 0

Views: 100

Answers (1)

M_Idrees
M_Idrees

Reputation: 2172

Change if condition from

if (row.Cells[11].Value.ToString().Equals(textBox1.Text))

to

if (row.Cells[11].Value.ToString().Replace(" ","").Equals(textBox1.Text))

Upvotes: 1

Related Questions