custom item in property grid

2 Answers 24 Views
PropertyGrid
F
Top achievements
Rank 1
Iron
F asked on 17 May 2022, 03:48 AM | edited on 17 May 2022, 06:01 AM

Hi.

Im tring to design a form like this to display some info. prop3 is a list of N string where N is variable. after i learnt some controls and found that property grid with custom item is accessible. i also read the custom item in property grid and tried, but i didnt get the result i want. 

in my code, i changed enum to list<string>. and item.deliveryType to item.prop3 which type is string.

  

btw, i use managed c++. thanks.

 

2 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 May 2022, 07:23 AM
Hello,   


I believe that you are using the demonstrated approach in the following help article:
https://docs.telerik.com/devtools/winforms/controls/propertygrid/custom-items

It shows how to generate RadRadioButtonElements for each item in an enum. However, when you have a property that is a List<string>, you wouldn't know how many elements exactly to generate in the CreateChildElements method. This place is too early for this because you don't have access to the data bound item yet. I have adopted this approach and used the Synchronize method to iterate the string values in a List.

Please give the sample project a try and see how it would work on your end. Feel free to use a similar approach to achieve the custom requirement that you have.

I hope this information helps. If you need any further assistance please don't hesitate to contact me.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

F
Top achievements
Rank 1
Iron
commented on 18 May 2022, 08:07 AM

thanks for ur answer. 

i've tried in a similar way and got a similar result. the way is that during rewriting CreateChildElements, i use RadGridViewElement rather than stackpanel with LightVisualElement inside. code is following

it works well, while i find another problem which aslo appears in ur way. i select whole value only but specific value/row i want in properties item when i kick the properties item.

is there any other way to archive my goal, i.e. virtual grid instead of property grid? i tried but not work. 

0
F
Top achievements
Rank 1
Iron
answered on 18 May 2022, 07:02 AM | edited on 18 May 2022, 07:03 AM

Hi, @Dess thks for ur reply.

i've tried in a similar way and got a similar result. the way is that i use RadGridViewElement directly rather than LightVisualElement embeded in stackpanel. code is following:

it works well too. while i find another problem. i can select whole value/string only but specific value in properties item.

so is there any other way to archieve my goal? i tried virtual grid instead of property grid but didt work.

Dess | Tech Support Engineer, Principal
Telerik team
commented on 20 May 2022, 11:06 AM

RadGridView is a heavy control to be used as a part of the property grid items. In addition, it can't be used as an element with the full arsenal of features it offers. A better option is to use a RadListView hosted in a RadHostItem. Thus you will achieve the item selection:

        public class CustomPropertyGridValueElement : PropertyGridValueElement
        {
            RadHostItem host;
            RadListView listViewElement;

            protected override void CreateChildElements()
            {
                base.CreateChildElements(); 
                listViewElement = new RadListView();
                listViewElement.ItemSize = new Size(100, 20); 
                host= new RadHostItem(listViewElement);
                this.Children.Add(host);
            } 

            public override void Synchronize()
            {
                PropertyGridItem item = this.VisualItem.Data as PropertyGridItem;
                Item dataBoundItem = item.PropertyGridTableElement.SelectedObject as Item;
                if (dataBoundItem != null && listViewElement.Items.Count==0)
                {

                    foreach (string prop in dataBoundItem.Properties)
                    {
                        listViewElement.Items.Add( prop);
                    }
                }
            }
        }

However, please have in mind that using controls in RadPropertyGrid items will cause visual glitches as controls do not support clipping. A better option would be using custom editors. Thus, you can construct the desired editor and activate it for the respective item: https://docs.telerik.com/devtools/winforms/controls/propertygrid/editors/using-custom-editor

   
Tags
PropertyGrid
Asked by
F
Top achievements
Rank 1
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
F
Top achievements
Rank 1
Iron
Share this question
or