Click here to Skip to main content
6,629,885 members and growing! (24,775 online)
Email Password   helpLost your password?
Languages » C / C++ Language » General     Intermediate License: The Code Project Open License (CPOL)

PropertyGrid Control in WinForms

By vivekthangaswamy

PropertyGrid control in WinForms.
C#, Windows, .NET 1.0, .NET 1.1VS.NET2003, Dev
Posted:21 Sep 2004
Updated:20 Oct 2005
Views:48,133
Bookmarked:20 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
75 votes for this article.
Popularity: 3.04 Rating: 1.62 out of 5
52 votes, 69.3%
1
6 votes, 8.0%
2
2 votes, 2.7%
3
2 votes, 2.7%
4
13 votes, 17.3%
5

Disclaimer:

This source code is written and maintained by an individual, not a company. It has been provided for free to the Microsoft .NET user community with the expectation that users will take whatever action necessary to get the code to operate according to their needs. This includes debugging and enhancements. The source code is provided "as is" and there are neither warrantees to the quality of the work nor any expressed or implied agreements that the programmer will release any updates. The programmer will release updates and provide any support at his own discretion.

Introduction:

The article is mainly to show how to use the PropertyGrid control in WinForms. Using this PropertyGrid control, we can change the property of other controls while at runtime.

This article is to give a simple example in C# showing how easy it is to use the PropertyGrid control in WinForms. This is developed using Visual Studio .NET final release. PropertyGrid provides a user interface for browsing the properties of an object.

Adding "PropertyGrid" to VS.NET Toolbox:

Select �Tools� menu and Select �Add/Remove Tool Box Items�. Then the �Customize Toolbox� will appear in the screen. Select �.NET Framework Component� tab and then select the �PropetyGrid� checkboxes and hit OK. Now you can drag and drop the �PropetyGrid� into the Windows Form.

Example:

In the example, I used the TextBox control for explanation.

public Form1()
{
    // The initial constructor code goes here.


    PropertyGrid propertyGrid1 = new PropertyGrid();
    propertyGrid1.CommandsVisibleIfAvailable = true;
    propertyGrid1.Location = new Point(10, 20);
    propertyGrid1.Size = new System.Drawing.Size(400, 300);
    propertyGrid1.TabIndex = 1;
    propertyGrid1.Text = "Property Grid";

    this.Controls.Add(propertyGrid1);
    propertyGrid1.SelectedObject = textBox1;
}

The above code is to add the PropertyGrid control to your WinForm. And the code will select the TextBox as the selected component. The information displayed in the grid is a snapshot of the properties at the time the object is assigned. If a property value of the object specified by the SelectedObject is changed in code at run time, the new value is not displayed until an action is taken in the grid that causes the grid to refresh.

  • PropertyGrid.SelectedObject

    Gets or sets the object for which the grid displays properties.

  • public object SelectedObject {get; set;}

    The SelectedObject property sets a single object into the grid to be browsed. If multiple objects are being browsed, this property returns the first one in the list. If no objects are selected, a null reference is returned.

The below mentioned is the PropertyGrid class signature.

public class PropertyGrid : ContainerControl

Any public static members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

To exit from the application, use the following code:

private void Exit_Click(object sender, System.EventArgs e)
{
    this.Dispose();
}

For more help and queries, please mail me at vivekthangaswamy@rediffmail.com.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

vivekthangaswamy


Member

Occupation: Architect
Location: India India

Other popular C / C++ Language articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 9 of 9 (Total in Forum: 9) (Refresh)FirstPrevNext
GeneralMy vote of 1 PinmemberGDMonkey0:58 29 Oct '09  
Generalwow! and you're an architect? this is the best you could come up with? Pinmemberjeffsaremi7:08 12 Jul '09  
GeneralMy vote of 1 Pinmemberjeffsaremi7:07 12 Jul '09  
GeneralUnethical PinmemberBubba Ole11:32 18 Jun '09  
GeneralMy vote of 1 PinmemberElTchoupi3:37 31 Mar '09  
GeneralMoron PinmemberNaveenChander0:51 21 Oct '08  
GeneralVery poor article Pinmemberrajeshkanakarajan15:26 13 Apr '08  
GeneralRe: Very poor article PinmemberDaeMan200123:19 25 May '08  
GeneralRe: Very poor Comments PinmemberAGC Blogger5:52 21 Sep '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 20 Oct 2005
Editor: Smitha Vijayan
Copyright 2004 by vivekthangaswamy
Everything else Copyright © CodeProject, 1999-2009
Web19 | Advertise on the Code Project