Results 1 to 12 of 12

Thread: [2005] Show File Properties

  1. #1

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    [2005] Show File Properties

    Dear all,

    How to show the File Properties in Property Gird

    dana
    Please mark you thread resolved using the Thread Tools as shown

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Show File Properties

    Probably best for reuse, create a class with the properties you are wanting to display in the PG. Then populate from the selected file. Then bind the class to the PG using the .SelectedObject property. Using attribute tags on your props designate how and where they are shown in the grid, if at all desired.

    VB Code:
    1. Imports System.ComponentModel
    2.  
    3. Public Class PropertyClass
    4.     Private mprop1 As String = "Text"
    5.     Private mprop2 As Integer = 1
    6.     Private mprop3 As Bitmap
    7.     Private mprop4 As Color = Color.Red
    8.  
    9.     <Category("Category1"), DefaultValue("Text")> _
    10.     Public Property Property1() As String
    11.         Get
    12.             Return mprop1
    13.         End Get
    14.         Set(ByVal Value As String)
    15.             mprop1 = Value
    16.         End Set
    17.     End Property
    18.  
    19.     <Category("Category1"), DefaultValue(1)> _
    20.     Public Property Property2() As Integer
    21.         Get
    22.             Return mprop2
    23.         End Get
    24.         Set(ByVal Value As Integer)
    25.             mprop2 = Value
    26.         End Set
    27.     End Property
    28.  
    29.     <Category("Category2")> _
    30.     Public Property Property3() As Bitmap
    31.         Get
    32.             Return mprop3
    33.         End Get
    34.         Set(ByVal Value As Bitmap)
    35.             mprop3 = Value
    36.         End Set
    37.     End Property
    38.  
    39.     <Category("Category2"), DefaultValue(GetType(Color), "Red")> _
    40.     Public Property Property4() As Color
    41.         Get
    42.             Return mprop4
    43.         End Get
    44.         Set(ByVal Value As Color)
    45.             mprop4 = Value
    46.         End Set
    47.     End Property
    48. End Class

    Example Usage:

    VB Code:
    1. Private mproperties As New PropertyClass
    2.     Private propGrid As New PropertyGrid
    3.  
    4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5.         propGrid.Location = New Point(10, 10)
    6.         propGrid.Size = New Size(200, 250)
    7.         propGrid.Dock = DockStyle.Fill
    8.         propGrid.CommandsVisibleIfAvailable = True
    9.         propGrid.Text = "My Property Grid"
    10.  
    11.         pnlPropGrid.Controls.Add(propGrid)
    12.  
    13.         propGrid.SelectedObject = mproperties
    14.     End Sub
    15.  
    16.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    17.         ' Save mproperties content here
    18.     End Sub
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2005] Show File Properties

    Dear Robert,
    Thanks for your reply.Now I found this code do display the default file properties.
    vb Code:
    1. PropertyGrid1.SelectedObject = New FileInfo("c:\test.txt")

    And now I can add some properties to this additionally
    Please mark you thread resolved using the Thread Tools as shown

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Show File Properties

    Cool, didnt think about doing it that way but if you want to override some of the default properties then you will need the intermediate class like I posted.
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2005] Show File Properties

    Can we able to add some extra property to inaddition to the default showing when this command is executed

    vb Code:
    1. PropertyGrid1.SelectedObject = New IO.FileInfo("filename.ext")
    Please mark you thread resolved using the Thread Tools as shown

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Show File Properties

    You can only show properties of the object that you've assigned to the SelectedObject property of the grid. If you want to show other properties then you'd have to assign a different type of object that has those properties. You can define your own type that wraps a FileInfo and provides those additional properties if you like.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2005] Show File Properties

    Dear JMC,
    Wheather I have to write a new wrapper for all the properties of the Fileinfo.Or just inherit the existing property and add my properties /
    Please mark you thread resolved using the Thread Tools as shown

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Show File Properties

    Which do you think would be better and why? Is there any impediment to doing it that way?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2005] Show File Properties

    I think inheriting the existing properties,adding new properties (mine) and showing is will be the best one
    Please mark you thread resolved using the Thread Tools as shown

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Show File Properties

    What benefit(s) does that provide? Is there any impediment to doing it that way? Is there any benefit to doing it the other way?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Show File Properties

    I think the question is what are you trying to accomplish? Just showing the default properties, showing and adding new properties, showing and overriding default properties, etc.
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  12. #12

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2005] Show File Properties

    Yes Robert,You are 200 % Correct
    Please mark you thread resolved using the Thread Tools as shown

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width