+ 1

C#;visual studio

how do I make a set of data selected by a user in a chekedlistbox of a form 1 on visual studio in c # in label on a form 2 visible?

25th Nov 2017, 10:50 PM
Pietro Colletti
Pietro Colletti - avatar
4 Respostas
+ 1
I've already public the chekedlistbox in form 1 so that you can bring the collection to all forms. in the chekedlistbox the data is of a string type and must be able to make the selected ones in some labels (or other objects) of form 2 visible
26th Nov 2017, 12:33 PM
Pietro Colletti
Pietro Colletti - avatar
0
What is the type of the elements in the checkedlistbox ? Do you need to know what the state of the elements is in form2 ?
26th Nov 2017, 12:24 PM
sneeze
sneeze - avatar
0
winform or wpf
26th Nov 2017, 6:47 PM
sneeze
sneeze - avatar
0
a example in Winform public partial class Form1 : Form { List<string> myFruit = new List<string>();//{ "Apples", "Oranges", "Tomato" }; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { myFruit.Add("Apples"); myFruit.Add("Oranges"); myFruit.Add("Tomato"); checkedListBox1.Items.AddRange(myFruit.ToArray()); Form2 DetailForm = new Form2(); foreach (string item in checkedListBox1.SelectedItems) { DetailForm.NewList.Add(item); } DetailForm.ShowDialog(); } } code of form2 public partial class Form2 : Form { private List<string> newList; public List<string> NewList { get { return newList; } set { newList = value; } } public Form2() { InitializeComponent(); } } I tried doing it with collections and passing collections but ended up with "cannot implicitly convert errors" So this is the simplest way to do it.
27th Nov 2017, 10:21 PM
sneeze
sneeze - avatar