Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > PropertyGrid > SelectedObject: the Grid will be initialized again

Not answered SelectedObject: the Grid will be initialized again

Feed from this thread
  • Sebastian avatar

    Posted on Dec 5, 2011 (permalink)

    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

    Reply

  • Ivan Petrov Ivan Petrov admin's avatar

    Posted on Dec 8, 2011 (permalink)

    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.

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.
  • Sebastian avatar

    Posted on Dec 8, 2011 (permalink)

    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
    Attached files

    Reply

  • Ivan Petrov Ivan Petrov admin's avatar

    Posted on Dec 12, 2011 (permalink)

    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.

    Reply

  • Sebastian avatar

    Posted on Dec 13, 2011 (permalink)

    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

    Reply

  • Ivan Petrov Ivan Petrov admin's avatar

    Posted on Dec 15, 2011 (permalink)

    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.

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > PropertyGrid > SelectedObject: the Grid will be initialized again