0

たとえば、dataGridView セルのフォーム 1 の単語は、one;two;three ..... です。

この表示は、テキストボックスの form2 で個別に行いたい:

text in textBox1: one
text in textBox2: two
text in textBox3: three

これを解析するにはどうすればよいですか?

このようにformOneにデータグリッドを埋めます:

foreach (DataGridViewCell cell in dataGridView1.SelectedCells)
        {

            string text = "";
            for (int i = 0; i < emails.Length ;i++)
            {

                if (emails[i].ToString().Trim() != "")
                {


                    text = text + emails[i] + ";"  ;
                    dataGridView1.Rows[cell.RowIndex].Cells[col].Value = text;
                }
            }

        }    
4

1 に答える 1

2
string cellValue = "one;two;three";
// should contain at least three values
var values = cellValue.Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries);
textBox1.Text = values[0];
textBox2.Text = values[1];
textBox3.Text = values[2];

セルで可能な値の数が異なる場合は、テックスボックスを動的に作成することも検討してください。別のオプションは、グリッドの使用です。


別のオプション - texboxes のリストを取得:

var textBoxes = new List<TextBox> { textBox1, textBox2, textBox3 };

または、texbox を正しい順序でフォームに追加する場合:

var textBoxes = Controls.OfType<TextBox>().ToList();

そして、それらすべてをループで埋めます

string cellValue = "one;two;three";
var values = cellValue.Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries);

for (int i = 0; i < values.Length; i++)
   if (textBoxes.Count < i) // also you can ensure you have textBox for value
       textBoxes[i].Text = values[i];
于 2013-08-01T09:42:03.427 に答える