The code below binds the rows from CheckedListBox1 to the Value1 and Value2 properties, which in turn are associated with TextBoxes. Please tell me how to fix the following problem in C # WinForms VS2010: you need the Value2 property (linked to TextBox2) to be the same for all the lines from CheckedListBox1, i.e. after binding, if text is entered into TextBox2, then for all the lines from CheckedListBox1 this text had the last value entered? Now for each line from CheckedListBox1, the value for TextBox2 is changing.

public class Person { public string Name { get; set; } public string Value1 { get; set; } public string Value2 { get; set; } } private void btn1_Click(object sender, EventArgs e) { people = new BindingList<Person>(); foreach (var item in CheckedListBox1.Items) { Person p = new Person { Name = item.ToString(), Value1 = TextBox1.Text, Value2 = TextBox2.Text, }; people.Add(p); } var listBox = ((ListBox)CheckedListBox1); listBox.DataSource = people; listBox.DisplayMember = "Name"; TextBox1.DataBindings.Clear(); TextBox2.DataBindings.Clear(); TextBox1.DataBindings.Add("Text", people, "Value1", false, DataSourceUpdateMode.OnPropertyChanged); TextBox2.DataBindings.Add("Text", people, "Value2", false, DataSourceUpdateMode.OnPropertyChanged); } 
  • those. do you have one of the properties should be the same for everyone? In the current implementation of the class Person, with the help of binding, this will not work. You need either a separate logic on the events, or the property should be really common, for example, based on a static field. - rdorn
  • I see, thanks! - olga

0