how to pass a substring or single character within datagridview

How can I pass substring or a single character within the datagridview. For example: I have a string like 'animal?species' I need to pass 'animal' to another cell of the datagridview, how can I do that ? Any help would be great, thank you.

EDIT:

private void keypress1(object sender, KeyPressEventArgs e)
    {
        if (dataGridView1.CurrentCell.ColumnIndex == 0 || dataGridView1.CurrentCell.ColumnIndex == 1)
        {
            if (e.KeyChar >= 48 && e.KeyChar <= 57 && e.KeyChar==8 ) {}
            else
            {                   
                e.Handled = true;                    
            }
        }
        if(dataGridView1.CurrentCell.ColumnIndex==4)
        {
            string test = "";
            if (e.KeyChar == 92)
            {
                dataGridView1.CurrentRow.Cells[7].Value = null;
                //dataGridView1.Columns["dom"].ReadOnly = true;  bad code
                test = dataGridView1.CurrentCell.Value.ToString();
                string[] splittedtest = test.Split('?');
                for (int i = 0; i < splittedtest.Length; i++)
                {
                    dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[7].Value = splittedtest[i];
                }
            }

        }
    } 

when it comes to test = dataGridView1.CurrentCell.Value.ToString(); nullexception occurs. I guess the reason is value are not submitted yet.

Answers


You can do with 'Split' function. this may give you a hint to proceed.

string test = "animal?species";
string [] splittedtest = string.Split(new Char[] { '?', '\' },
                             StringSplitOptions.RemoveEmptyEntries);
//string[] splittedtest = test.Split('?');
for(int i = 0;i<splittedtest.length;i++)
{
   // do your stuffs like below,  
   // DataGridView1.Rows[DataGridView.SelectedRows[0].Index].Cells[X].Text = splittedtest[i];
   // where X is the column you want to read. 
}

Need Your Help

Multiple values with same tag

javascript json api

Okay, so I have the following code, which is supposed to search Urban Dictionary for a certain term and then log the definition to the console:

Rails link_to working wierd

ruby-on-rails link-to

I have set up a link_to in a partial (update_dashboard) and it looks like this