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

SelectedObject: the Grid will be initialized again

5 Answers 66 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Sebastian
Top achievements
Rank 2
Sebastian asked on 05 Dec 2011, 06:31 PM
I have the problem that, when i use the SelectedObject method from the propertygrid then will be the grid initialized again.
and the current view from the grid will be set to the default view.  for example (all open properties will be closed)

the WindowsForm PropertyGrid do this not!
how can i change this behavior?

BR
Sebastian

5 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 08 Dec 2011, 10:30 AM
Hi Sebastian,

Thank you for writing.

We will consider implementing this scenario in one of our future releases if there is growing demand for this feature. For now you can use the following workaround method to set the RadPropertyGrid SlectedObject:

private void SetNewSelectedObject(object newSelectedObject)
{
  string propertyName = String.Empty;
  int scrollValue = 0;
  bool sameType = false;
 
  if (this.radPropertyGrid1.SelectedObject != null && this.radPropertyGrid1.SelectedGridItem != null)
  {
    sameType = this.radPropertyGrid1.SelectedObject.GetType() == newSelectedObject.GetType();
    propertyName = this.radPropertyGrid1.SelectedGridItem.Name;
 
    if (sameType)
    {
      scrollValue = this.radPropertyGrid1.PropertyGridElement.PropertyTableElement.VScrollBar.Value;
    }
  }
 
  this.radPropertyGrid1.SelectedObject = newSelectedObject;
 
  this.radPropertyGrid1.SelectedGridItem = this.radPropertyGrid1.Items[propertyName];
  if (this.radPropertyGrid1.SelectedGridItem != null)
  {
    if (sameType)
    {
      this.radPropertyGrid1.PropertyGridElement.PropertyTableElement.VScrollBar.Value = scrollValue;
    }
    else
    {
      this.radPropertyGrid1.SelectedGridItem.EnsureVisible();
    }
  }
}

I hope this will help you. Should you need further assistance, I would be glad to provide it.
Kind regards,
Ivan Petrov
the Telerik team

Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

0
Sebastian
Top achievements
Rank 2
answered on 08 Dec 2011, 11:30 AM
Hello Ivan,

thanks for your reply but this will be only work for the scolling postion.
what i need is the postition/state of the opening collections . this is very disturb when all open collections closed after ...selectedobject

for example see the picture in the attachment

thanks for your help
BR
Sebastian
0
Ivan Petrov
Telerik team
answered on 12 Dec 2011, 05:43 PM
Hello Sebastian,

Thank you for your reply and for the attached screen shot.

I understand your demand and I have prepared a sample project which extends my previous post. In the solution you will find a form with a property grid and two buttons clicking on the buttons will set them as the selected object of the property grid and will preserve the visual state of the property grid.

I hope you will find this helpful. If there is anything else I can help with, I would be glad to do so.

Kind regards,
Ivan Petrov
the Telerik team

Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

0
Sebastian
Top achievements
Rank 2
answered on 13 Dec 2011, 10:01 AM
Hi Ivan,

yes thank you very much, this is it what i'm looking for.

i have found a little error in this code, when you don't expand an collection and select a new object then you get a null exception.
when you check this before then is the code perfect (i have fix this for me)

it is possible to set this code as default or as an option in the next version of the propertygrid ?

thanks for the great support.
BR
Sebastian
0
Ivan Petrov
Telerik team
answered on 15 Dec 2011, 05:03 PM
Hello Sebastian,

Thank you for writing back.

I am glad we have found a way through this. Now that we have the code it will be easier to include it in the actual RadPropertyGrid. We will consider this feature when we plan our future releases. 

If you have other questions feel free to write again.

All the best,
Ivan Petrov
the Telerik team

Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

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