Hi,
Is it possible to keep tracking last selected property ? i.e user expanded couple of levels down to some property Xafter changing selected object I would like to automatically expand the properties down to the same property X if it is the same object type with the same properties so the user dos not have to do it manually over and over again when he want to compare property X between instances ?
Best regardsKrzysztof
Hello Krzysztof,
Thank you for contacting Infragistics Developer Support.
You can use the SelectedItem property and store it to keep track of the last selected item. You can also use the SelectedItemChanged event which will have both the old and new selected item so you can compare them. And the PropertyGridProertyItem will have information on that item:
www.infragistics.com/.../infragisticswpf.controls.editors.xampropertygrid~infragistics.controls.editors.xampropertygrid~selecteditem
www.infragistics.com/.../infragisticswpf.controls.editors.xampropertygrid~infragistics.controls.editors.xampropertygrid~selecteditemchanged_ev
www.infragistics.com/.../infragisticswpf.controls.editors.xampropertygrid~infragistics.controls.editors.propertygridpropertyitem
Hi Michael,
it is a little bit different scenario and this will not work that easy ...it is not only the case to remember the last selected propertyitem for an selectedobject -> when different instance is displayed in propertygrid I want to expand down to the property with the same name (in fact in the same path) programmatically as user did for first instance
lets assume you have on the left side list of an objects X, on the right the property grid1. user selects X1 -> PropertyGrid.SelectedObject = X12. user expands the properties i.e RootProp -> Prop1 -> Prop2 -> and selects 'Name'3. user selects from the list different object -> PropertyGrid.SelectedObject = X2 here I want to expand down to the 'Name' for this instance of X, at this point the Prop1, Prop2 and Name are not yet generatedalso without reflection it is not possible to get the properties path -> SourceObject of PropertyGridPropertyItem is internal as well as ParentItem property.
so the question is:when SelectedObject is changed to different instance of an object X how to programmatically expand multiple levels down to specific property ?P.Seither calling Select() on a PropertyGridPropertyItem or assiging PropertyGrid.SelectedItem does not workBest regards,Krzysztof
Thank you for the update. If you want to expand an item you would set IsExpanded on the item to true. You would then look at the children collection to get its children and proceed down the chain.
www.infragistics.com/.../infragisticswpf.controls.editors.xampropertygrid~infragistics.controls.editors.propertygriditem~isexpanded
www.infragistics.com/.../infragisticswpf.controls.editors.xampropertygrid~infragistics.controls.editors.propertygriditem~children
www.infragistics.com/.../infragisticswpf.controls.editors.xampropertygrid~infragistics.controls.editors.propertygriditem_members
sorry, it does not work, please find attached sample, it crashes the app (nullref exc in xampropertygrid)really wasted too much time on sth what should be simple functionality and it needs hacks (reflection)please look at the sample app (used latest 2020 version).Best regards,Krzysztof1007.WpfApp2.zip
I have debugged your method a couple times, You find the first item in the list and try and hand out that. The reason seems to be use of the method FirstOrDefault. You will want find the correct item and then try and expand that.
Please double check the sample and debug it instead of quick look at the code.1. properties are generated by custom generator and setter of IsExpandable is internal, even hacking and setting it by reflection, when expanding it in the code nullreferenceexception is thrown - it works for first level, for second expandable item ('expandable further') the PropertyGrid property of the item is null
2. no, functions looks for correct items, please double check and debug
Thank you for the update. The error is occurring because you are trying to expand an item that isn’t expandable, you will want to check IsExpandable before expanding and item:
if (itemToSelect.IsExpandable)
Also your function seems to just grab the first item in the property grid instead of looking for the next item to expand.
yes, please expand the first property 3 levels down, select the last expanded (1.)and click 'change object' button (2.)
Thank you for the update and sample. I use the v20.1.20201.9 dlls in your sample and I don’t experience a crash. Do you have steps you use to reproduce the issue?
Sincerely,Mike P.Software Developer