Feb 1st, 2005, 01:50 PM
#1
Property Grid Usage [Resolved]
I finally foud the property grid thanks to Aaron Young in this thread , but I
am having some trouble implementing it on my user control. Does anyone
know how it works?
Thanks in advance for any assistance.
Last edited by RobDog888; Jun 21st, 2005 at 06:00 PM .
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Feb 1st, 2005, 06:12 PM
#2
Re: Property Grid Usage
What exactly are you having trouble doing?
All you should have to do is set the SelectedObject property to the control/class you want to set properties for.
Feb 1st, 2005, 06:35 PM
#3
Re: Property Grid Usage
the property grid control is ONLY for displaying properties of objects(programming objects).
If you were expecting to be able to just do a PropertyGrid1.AddItem("ItemName", "Value", "Category") you will be disappointed.
You could decompile the control....
Tips:
Google is your friend! Search before posting!Name your thread appropriately... "I Need Help" doesn't cut it! Always post your code!!!! We can't read your mind!!! (well, at least most of us!) Allways Include the Name and Line of the Exception (if one is occuring!) If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post
IRC Contact: Rizon /xous ChakraNET /xous Freenode /xous
Feb 1st, 2005, 07:01 PM
#4
Re: Property Grid Usage
It's not as bad as it sounds, all you'd have to do is create a class that is comprised of the Properties you want to offer/manipulate, i.e.
VB Code:
Imports System.ComponentModel
Public Class PropertyClass
Private m_prop1 As String = "Text"
Private m_prop2 As Integer = 1
Private m_prop3 As Bitmap
Private m_prop4 As Color = Color.Red
<Category("Category1"), DefaultValue("Text")> _
Public Property Property1() As String
Get
Return m_prop1
End Get
Set(ByVal Value As String)
m_prop1 = Value
End Set
End Property
<Category("Category1"), DefaultValue(1)> _
Public Property Property2() As Integer
Get
Return m_prop2
End Get
Set(ByVal Value As Integer)
m_prop2 = Value
End Set
End Property
<Category("Category2")> _
Public Property Property3() As Bitmap
Get
Return m_prop3
End Get
Set(ByVal Value As Bitmap)
m_prop3 = Value
End Set
End Property
<Category("Category2"), DefaultValue(GetType(Color), "Red")> _
Public Property Property4() As Color
Get
Return m_prop4
End Get
Set(ByVal Value As Color)
m_prop4 = Value
End Set
End Property
End Class
Example Usage:
VB Code:
Private m_properties As New PropertyClass
Private propGrid As New PropertyGrid
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
propGrid.Location = New Point(10, 10)
propGrid.Size = New Size(200, 250)
propGrid.Dock = DockStyle.Fill
propGrid.CommandsVisibleIfAvailable = True
propGrid.Text = "My Property Grid "
pnlPropGrid.Controls.Add(propGrid)
propGrid.SelectedObject = m_properties
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Save m_properties content here
End Sub
Feb 1st, 2005, 09:25 PM
#5
Re: Property Grid Usage
Ok, but I am having trouble with it when I try to integrate it to a form for my
user control. In my control I have a property - Panels (collection) that I am
trying to get the elipsis to appear and when that is clicked it will bring up my
property form with the property grid on it and a listbox to add/remove panels.
Nowe I need each entry of the listbox to have its own properties and as you
click each one the properties will change accordingly.
I have another thread where I am trying to get the elipsis and hyperlink text
for an About link in the description for my control.
Thats all nothing complicated
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Feb 2nd, 2005, 12:17 AM
#6
Re: Property Grid Usage
You need to create a custom Collection Editor, here's an example:
MyPanel Class:
VB Code:
Imports System.ComponentModel
Public Class MyPanel
Private m_name As String = ""
Private m_prop1 As String = ""
<Browsable(True), DefaultValue("")> _
Public Property Name() As String
Get
Return m_name
End Get
Set(ByVal Value As String)
m_name = Value
End Set
End Property
<Browsable(True), DefaultValue("")> _
Public Property Property1() As String
Get
Return m_prop1
End Get
Set(ByVal Value As String)
m_prop1 = Value
End Set
End Property
Public Overrides Function ToString() As String
Return m_prop1
End Function
End Class
MyPanels Class:
VB Code:
Public Class MyPanels
Inherits CollectionBase
Default Public ReadOnly Property Item(ByVal index As Integer) As MyPanel
Get
Return List(index)
End Get
End Property
Public Function Add(ByVal value As MyPanel) As Integer
Return List.Add(value)
End Function
Public Sub Remove(ByVal value As MyPanel)
List.Remove(value)
End Sub
Public Function Contains(ByVal value As MyPanel) As Boolean
Return List.Contains(value)
End Function
Public Function IndexOf(ByVal value As MyPanel) As Integer
Return List.IndexOf(value)
End Function
End Class
PanelCollectionEditor Class:
VB Code:
Public Class PanelCollectionEditor
Inherits System.ComponentModel.Design.CollectionEditor
Private m_id As Integer = 1
Public Sub New(ByVal type As System.Type)
MyBase.New(type)
End Sub
Protected Overrides Function CreateNewItemTypes() As Type()
' Return an Array of Types this editor can manage
Dim types(0) As Type
types(0) = GetType(MyPanel)
Return types
End Function
Protected Overrides Function CreateInstance(ByVal itemType As Type) As Object
' Create a new Panel instance
Dim panel As MyPanel
panel = MyBase.CreateInstance(itemType)
panel.Name = "Panel" & m_id
m_id += 1
Return panel
End Function
Protected Overrides Function SetItems(ByVal editValue As Object, ByVal value() As Object)
' Load the list of Panels into the Editor
Dim panel As MyPanel
Dim panels As MyPanels
panels = editValue
For Each panel In value
panels.Add(panel)
Next
Return editValue
End Function
End Class
MyControl Class:
VB Code:
Imports System.ComponentModel
Public Class MyControl
Private m_panels As New MyPanels
Private m_text As String = "Something"
<Bindable(True), DefaultValue("Something")> _
Public Property Text() As String
Get
Return m_text
End Get
Set(ByVal Value As String)
m_text = Value
End Set
End Property
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
Editor(GetType(PanelCollectionEditor), GetType(System.Drawing.Design.UITypeEditor))> _
Public ReadOnly Property Panels() As MyPanels
Get
Return m_panels
End Get
End Property
End Class
Example:
VB Code:
Private m_control As New MyControl
Private propGrid As New PropertyGrid
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
propGrid.Location = New Point(10, 10)
propGrid.Size = New Size(200, 250)
propGrid.Dock = DockStyle.Fill
propGrid.CommandsVisibleIfAvailable = True
propGrid.Text = "My Property Grid "
pnlPropGrid.Controls.Add(propGrid)
propGrid.SelectedObject = m_control
End Sub
Feb 2nd, 2005, 12:28 AM
#7
Re: Property Grid Usage
Thank you Aaron for going to the trouble and detail for me. I will try implementing it tonight.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Feb 3rd, 2005, 05:02 PM
#8
Re: Property Grid Usage
I didnt get to it last night, so hopefully tonight. I just wanted to post a link that is
relevant to the thread in case anyone has this issue with the PG.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Feb 18th, 2005, 12:27 AM
#9
Re: Property Grid Usage
Ok, I got a little farther until I hit this. Everytime I click the elipsis button in my test project
and add a new panel to the UIEditor and click ok, when I click it a second time to bring up the editor
again it adds another duplicate panel item to the collection. I can not remove them either.
I know it has to do with the MyPanels class code perhaps?
Attached Images
Last edited by RobDog888; Feb 18th, 2005 at 12:31 AM .
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Feb 18th, 2005, 04:00 PM
#10
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Feb 18th, 2005, 11:10 PM
#11
Re: Property Grid Usage
Try this instead, it seems I made a mistake in my first attempt at a custom Collection Editor, this seems to work the way you want:
VB Code:
Public Class PanelCollectionEditor
Inherits System.ComponentModel.Design.CollectionEditor
Private m_id As Integer = 1
Public Sub New(ByVal type As System.Type)
MyBase.New(type)
End Sub
Protected Overrides Function CreateNewItemTypes() As Type()
' Return an Array of Types this editor can manage
Dim types(0) As Type
types(0) = GetType(MyPanel)
Return types
End Function
Protected Overrides Function CreateInstance(ByVal itemType As Type) As Object
' Create a new Panel instance
Dim panel As MyPanel
panel = MyBase.CreateInstance(itemType)
panel.Name = "Panel" & m_id
m_id += 1
Return panel
End Function
End Class
Feb 18th, 2005, 11:27 PM
#12
Re: Property Grid Usage
Thanks, I'll give it a try.
Quick question: I am having trouble with the Panel class. Seems like I need a nested collection of items
in each Panel class. I dont know if this is the correct design but I dont se how to have settings for
the items in each Panel?
I have a small thread on the start of it here .
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Feb 19th, 2005, 12:22 AM
#13
Re: Property Grid Usage
Ok I found a control that will be a good example of what panels, Panel, Items, and Item I need to duplicate
for my control.
The listview control has an Items collection and when you click on it, that brings up the Items editor.
Then you can add a item and for each item you add you have a subitems collection that is
for each item. When you click the subitems collection you get another popup SubItems editor. Basically it
has two editors that are daisy chained off of each other.
So I need a Panels collection editor where I can add/remove a Panel. Then for each Panel I would have a Items
collection editor where I could add/remove Items for each Panel.
Hope I didnt confuse anyone
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Feb 19th, 2005, 12:58 AM
#14
Re: Property Grid Usage
Ok, I added another procedure to the editor -
VB Code:
Protected Overrides Sub DestroyInstance(ByVal instance As Object)
Dim panel As MyPanel
MyBase.DestroyInstance(m_id)
End Sub
Only problem so far is that when an item is removed from the collection and a new items it added,
it doesnt pickup from the number that was left off. For ex. If I created three panels and removed the third one (Panel3),
then added back another one, it will continue at Panel4 instead of Panel3.
It does this with or without the DestroyInstance procedure also.
I also found this method - MyBase.CreateCollectionForm. Would this be for when you need to display a
secondary nested collection for a collection item?
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Feb 23rd, 2005, 06:26 PM
#15
Re: Property Grid Usage
If this is too much then what about creating my own Editor which I could add the functionality
that I dont know how to duplicate?
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width