SelectedObject: the Grid will be initialized again

6 posts, 0 answers
  1. Sebastian
    Sebastian avatar
    7 posts
    Member since:
    Aug 2012

    Posted 05 Dec 2011 Link to this post

    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

  2. Ivan Petrov
    Admin
    Ivan Petrov avatar
    692 posts
    Member since:
    Sep 2012

    Posted 08 Dec 2011 Link to this post

    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.

  3. DevCraft Release
  4. Sebastian
    Sebastian avatar
    7 posts
    Member since:
    Aug 2012

    Posted 08 Dec 2011 Link to this post

    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

  5. Ivan Petrov
    Admin
    Ivan Petrov avatar
    692 posts
    Member since:
    Sep 2012

    Posted 12 Dec 2011 Link to this post

    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.

  6. Sebastian
    Sebastian avatar
    7 posts
    Member since:
    Aug 2012

    Posted 13 Dec 2011 Link to this post

    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

  7. Ivan Petrov
    Admin
    Ivan Petrov avatar
    692 posts
    Member since:
    Sep 2012

    Posted 15 Dec 2011 Link to this post

    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.

Back to Top
DevCraft Release