Как сохранить данные текстового поля для выбранного элемента в списке? - PullRequest
0 голосов
/ 03 июня 2019

Здесь я создал двумерный массив, в котором данные в текстовом поле должны храниться в выбранном элементе в списке. Он не работает, пожалуйста, помогите мне выбраться из этого кода

public partial class Form1 : Form
{
   public TextBox[] tb { get; private set; }
   public TextBox[] t { get; private set; }
   public TextBox[] t1 { get; private set; }
  // TextBox[][] textBoxes = { tb, t, t1 };

    public Form1()
    {
      InitializeComponent();
      TextBox[][] textBoxes = { tb, t, t1 };
      for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 5; j++)
            {
                 textBoxes[i][j] = new TextBox();
             }
        }
    }

    private void listBox1_Click(object sender, EventArgs e)
    {
      TextBox[][] textBoxes = { tb, t, t1 };
        int index = listBox1.SelectedIndex;
        textBox1.Text = tb[index][0].Text;
        textBox2.Text = tb[index][1].Text;
        textBox3.Text = tb[index][2].Text;
        textBox4.Text = tb[index][3].Text;
        textBox5.Text = tb[index][4].Text;
 }

   private void button1_Click_1(object sender, EventArgs e)
    {
        int index = listBox1.SelectedIndex;
        textBoxes [index][0].Text = textBox1.Text;
        textBoxes[index][1].Text = textBox2.Text;
        textBoxes[index][2].Text = textBox3.Text;
        textBoxes[index][3].Text = textBox4.Text;
        textBoxes[index][4].Text = textBox5.Text;

    }
}

1 Ответ

0 голосов
/ 03 июня 2019

Используйте это:

int pos = listBox1.Items.IndexOf(listBox1.SelectedItem.ToString());
if (pos != -1) listBox1.Items[pos] = textBox1.Text;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...