我的窗口中有 3 个列表框、3 个 texboxes、3 个按钮,当我将 listbox1 中的数据输入到 textbox1 并单击按钮或输入时,其他 2 个相同索引的列表框项目应该出现在其他 2 个文本框中。
这是写到现在的代码
private void Get_Click(object sender, RoutedEventArgs e)
{
int x = listbox1.SelectedIndex;
listbox2.SelectedIndex = x;
listbox3.SelectedIndex = x;
ListBoxItem lb1 = (listbox1.SelectedItem as ListBoxItem);
tb1.Text = lb1.Content.ToString();
ListBoxItem lb2 = (listbox2.SelectedItem as ListBoxItem);
tb2.Text = lb2.Content.ToString();
ListBoxItem lb3 = (listbox3.SelectedItem as ListBoxItem);
tb3.Text = lb3.Content.ToString();
}
private void Add_Click(object sender, RoutedEventArgs e)
{
int x = listbox1.SelectedIndex;
listbox2.SelectedIndex = x;
listbox3.SelectedIndex = x;
listbox1.Items.Add(tb1.Text);
listbox2.Items.Add(tb2.Text);
listbox3.Items.Add(tb3.Text);
}
private void Delete_Click(object sender, RoutedEventArgs e)
{
int x = listbox1.SelectedIndex;
listbox2.SelectedIndex = x;
listbox3.SelectedIndex = x;
listbox1.Items.RemoveAt(listbox1.Items.IndexOf(listbox1.SelectedItem));
listbox2.Items.RemoveAt(listbox2.Items.IndexOf(listbox2.SelectedItem));
listbox3.Items.RemoveAt(listbox3.Items.IndexOf(listbox3.SelectedItem));
}