This is a migrated thread and some comments may be shown as answers.

Change Value in Editor with value parameter

1 Answer 247 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
samuel
Top achievements
Rank 1
samuel asked on 07 Nov 2011, 07:08 PM
Hello,
I wish that as value of property values ​​change in my editor. For example I pass a value to the ID property, I would like with Red or Blue as a possibility and if I go 2 in value to the property ID, I would like to have Green and Black. Is this possible?

In my form
private void radPropertyGrid1_EditorRequired(object sender, PropertyGridEditorRequiredEventArgs e)
{
    if (e.Item.Name == "TestSam")
    {
        PropertyGridSamEditor test = new PropertyGridSamEditor();
        test.id = 1;
        e.EditorType = test.GetType();
    }
}

In my class PropertyGridSamEditor :
public class PropertyGridSam2Editor : BaseInputEditor
    {
        public PropertyGridSam2Editor()
        {
            m_ID = 0;
        }
        public int m_ID { get; set; }
        public PropertyGridSam2Editor(int ID)
        {
            m_ID = ID;
        }
        public override object Value
        {
            get
            {
                RadDropDownListElement editor = (RadDropDownListElement)this.EditorElement;
                List<InfoSam> Isam = new List<InfoSam>();
                if (m_ID == 0)
                {
                    Isam.Add(new InfoSam(1, "Rouge"));
                    Isam.Add(new InfoSam(2, "Bleu"));
                }
                else
                {
                    Isam.Add(new InfoSam(3, "Bleu"));
                    Isam.Add(new InfoSam(4, "Noir"));
                }
                editor.DisplayMember = "Couleur";
                editor.SelectedValue = "ID";
                editor.DataSource = Isam;
                return editor.Text;
            }
            set
            {
                RadDropDownListElement editor = (RadDropDownListElement)this.EditorElement;
                if (value != null && value != DBNull.Value)
                {
                    editor.Value = value.ToString();
                }
                else
                {
                    editor.Value = "1";
                }
            }
        }
}


Regards


1 Answer, 1 is accepted

Sort by
0
Accepted
Ivan Petrov
Telerik team
answered on 10 Nov 2011, 11:06 AM
Hi Samuel,

Thank you for writing and for the code snippets.

I have attached a sample project where I tried to replicate your scenario. I changed the type your editor inherits from BaseInputeEditor to PropertyGridDropDownListEditor. This way you would have more functionality and not have to implement it yourself. I have also moved your logic from the Value property to the Initialize method override. One thing left unresolved and that is what is the type of the property in the property grid. You have to return a value with the same type from the editor but I couldn't figure out what the type of the "TestSam" property is. For the example I have made it a string, so the editor can edit it. This is needed, because you have to set a ValueMember for the drop down editor element. You have set the DisplayMember, but you have not set the this way you won't be able to set the SelectedValue of the editor element. 

I hope this example will help you. If you need further assistance, I would be glad to provide it.

Greetings,
Ivan Petrov
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

Tags
PropertyGrid
Asked by
samuel
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Share this question
or