S
S
Sergey Khlopov2017-10-18 09:57:16
C++ / C#
Sergey Khlopov, 2017-10-18 09:57:16

How to make a connection between objects in a propertygrid?

Hello, tell me please, here I have two propertygrids . It is
59e6f8ba9057d749364053.jpeg
necessary to make it so that the field from the right object can be associated with some field from the left object. Here I think now how to receive these fields. It's just that these are the class objects that are added to the propertygrid, they are derived from this class

public class ClassNew
    {
        public int IDObj = 0;
        public string nameObj;
        public int Counter = 0;
        public object CloneObj()
        {
            this.Counter++;
            return this.MemberwiseClone();
        }
    }

And they are added to the propertygrid like this:
List<ClassNew> Array_Get_object = new List<ClassNew>(); //Коллекция объектов которые переданы для связи
        
private void CollectBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox NewSelect = sender as ComboBox;
            foreach(ClassNew Obj_selectI in Array_Get_object)
            {
                if (NewSelect.Name == CollectBox1.Name && NewSelect.SelectedItem.ToString() == Obj_selectI.nameObj)
                {
                    propertyGrid1.SelectedObject = Obj_selectI;
                }
                else if (NewSelect.Name == CollectBox2.Name && NewSelect.SelectedItem.ToString() == Obj_selectI.nameObj)
                {
                    propertyGrid2.SelectedObject = Obj_selectI;
                }
            }
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Nemiro, 2017-10-18
@AlekseyNemiro

The essence of the question is not fully understood. Is it necessary that, for example, changing the value of property A of the first class, these changes are reflected in the property X of the second class?
If so, then you probably need to look towards the PropertyValueChanged event :

private void propertyGrid1_PropertyValueChanged(Object sender, PropertyValueChangedEventArgs e) 
{
  System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();

  messageBoxCS.AppendFormat("{0} = {1}", "ChangedItem", e.ChangedItem );
  messageBoxCS.AppendLine();

  messageBoxCS.AppendFormat("{0} = {1}", "OldValue", e.OldValue );
  messageBoxCS.AppendLine();

  MessageBox.Show(messageBoxCS.ToString(), "PropertyValueChanged Event" );
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question