Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
PropertyGrid Manipulation
Message
De
23/08/2004 06:04:14
 
 
À
23/08/2004 03:37:47
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00935467
Message ID:
00935484
Vues:
17
Mike,

You have a couple of alternatives. You could create a proxy class that acts as a middle man to only those properties that are required for editing and instruct the PropertyGrid to reflect an instance of this object using the SelectedObject member.
public Form1()
{
   //
   // Required for Windows Form Designer support
   //
   InitializeComponent();

   //
   // TODO: Add any constructor code after InitializeComponent call
   //
   thePen = new Pen(System.Drawing.Color.Black);
   penProps = new PenProperties(thePen);
   penProps.PropertyChanged += new EventHandler(this.OnPenPropertyChangedEventHandler);

   propertyGrid1.SelectedObject = penProps;
   propertyGrid1.Refresh();
}


public class PenProperties 
{
 
   //Implementation members
   private System.Drawing.Pen thePen;
   private System.Drawing.Icon icon;

   //Events
   public event EventHandler PropertyChanged;
 
   //Properties
   [Description("The colour associated with the control"),Category("Appearance")]
   public System.Drawing.Color Color 
   {
      get {  return thePen.Color; }
      set 
      {
      thePen.Color = value;
      OnPropertyChanged( new EventArgs( ) );
      }
   }
 
   public System.Drawing.Drawing2D.DashCap DashCap 
   {
      get {  return thePen.DashCap; }
      set 
      {
         thePen.DashCap = value;
         OnPropertyChanged( new EventArgs( ) );
      }
   }
 
   public System.Drawing.Drawing2D.DashStyle DashStyle 
   {
      get {  return thePen.DashStyle; }
      set 
      {
         thePen.DashStyle = value;
         OnPropertyChanged( new EventArgs( ) );
      }
   }
 
   public float Width 
   {
      get {  return thePen.Width; }
      set 
      {
         thePen.Width = value;
         OnPropertyChanged( new EventArgs( ) );
      }
   }
 
   public float DashOffset 
   {
      get {  return thePen.DashOffset; }
      set 
      {
         thePen.DashOffset = value;
         OnPropertyChanged( new EventArgs( ) );
      }
   }

   public System.Drawing.Drawing2D.LineCap StartCap 
   {
      get {  return thePen.StartCap; }
      set 
      {
         thePen.StartCap = value;
         OnPropertyChanged( new EventArgs( ) );
      }
   }
 
   public System.Drawing.Drawing2D.LineCap EndCap 
   {
      get {  return thePen.EndCap; }
      set 
      {
         thePen.EndCap = value;
         OnPropertyChanged( new EventArgs( ) );
      }
   }

   public System.Drawing.Icon Icon 
   {
      get { return icon; }
      set
      {
         icon = value;
      }
   }

   public PenProperties(Pen p) 
   {
      thePen = p;
      thePen.EndCap = EndCap;
      thePen.Color = System.Drawing.Color.Black;
   }   
 
   protected void OnPropertyChanged( EventArgs e ) 
   {
      if( PropertyChanged != null )
         PropertyChanged( this, e );
      }
   }
}
The downside to doing this is you may end up with lots of different classes doing similiar things scattered about your code base. As an alternative you could engineer some type of collection class that implements the following interface.
System.ComponentModel.ICustomTypeDescriptor
This interface will allow your collection class to publish customised type information to the property grid in a more generic fashion. This would take a lot more effort to implement but it would provide a better solution to your problem.

Regards
Neil
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform