Results 1 to 4 of 4

Thread: multiline text in propertyGrid?

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    multiline text in propertyGrid?

    Is there a way to make the property grid show a multiline textbox for an item?

    if not, how would I make it show a dialog for a certain property? (to allow the user enter multiline text)
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: multiline text in propertyGrid?

    bump
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3
    Addicted Member
    Join Date
    Sep 2005
    Posts
    163

    Re: multiline text in propertyGrid?

    Just in case you have not resolved this .... I found this example while looking to resolve another PropertyGrid problem I have:
    The property:
    VB Code:
    1. Imports System.ComponentModel
    2. Imports System.Windows.Forms.Design
    3. Imports System.Drawing.Design  'Must reference System.Design.Dll
    4. Imports System.Globalization
    5. #Region " Custom editor "
    6.     <Category("Custom editor"), _
    7.     Editor(GetType(MultiLineStringEditor), GetType(UITypeEditor)), _
    8.     Description("Click on elipsis to open the editor.")> _
    9.     Public Property Description() As MultiLineString
    10.         Get
    11.             Return mLongStringProperty
    12.         End Get
    13.         Set(ByVal Value As MultiLineString)
    14.             mLongStringProperty = Value
    15.         End Set
    16.     End Property
    17. #End Region ' Custom Editor

    VB Code:
    1. Imports System.ComponentModel
    2. Imports System.Drawing.Design
    3. Imports System.Windows.Forms.Design
    4. Public Class MultiLineString
    5.     ' this is the custom type we'll want to edit in the propertygrid
    6.     ' it's just a class with 1 property, a string, but we want a multiline editor for it
    7.     Private mString As String
    8.     Private mS As String
    9.  
    10.     Public Sub New()
    11.  
    12.     End Sub
    13.     Public Sub New(ByVal s As String)
    14.         mString = s
    15.     End Sub
    16.     Public Property Value() As String
    17.         Get
    18.             Return mString
    19.         End Get
    20.         Set(ByVal Value As String)
    21.             mString = Value
    22.         End Set
    23.     End Property
    24.     Public Overrides Function ToString() As String
    25.         Return IIf(mString = "", "", "<...>").ToString
    26.     End Function
    27. End Class
    28.  
    29.  
    30. Public Class MultiLineStringConverter
    31.     Inherits System.ComponentModel.TypeConverter
    32.  
    33.     Public Overloads Overrides Function CanConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As System.Type) As Boolean
    34.         ' if you return true here (if sourceType Is GetType(String) Then Return True),
    35.         ' users will be able to edit the multiline property in the
    36.         ' propertygrid without using the editor
    37.         Return MyBase.CanConvertFrom(context, sourceType)
    38.     End Function
    39.  
    40.     Public Overloads Overrides Function CanConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As System.Type) As Boolean
    41.         If destinationType Is GetType(String) Then Return True
    42.         Return MyBase.CanConvertFrom(context, destinationType)
    43.     End Function
    44.  
    45.     Public Overloads Overrides Function ConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object) As Object
    46.         If TypeOf value Is String Then
    47.             Try
    48.                 Return New MultiLineString(value.ToString)
    49.             Catch
    50.                 Throw New InvalidCastException(value.ToString)
    51.             End Try
    52.         End If
    53.         Return MyBase.ConvertFrom(context, culture, value)
    54.     End Function
    55.  
    56.     Public Overloads Overrides Function ConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object, ByVal destinationType As System.Type) As Object
    57.         If (destinationType.Equals(GetType(String))) Then
    58.             Return value.ToString()
    59.         Else
    60.             Return MyBase.ConvertTo(context, culture, value, destinationType)
    61.         End If
    62.     End Function
    63.  
    64. End Class
    65.  
    66.  
    67. Public Class MultiLineStringEditor
    68.     Inherits UITypeEditor
    69.     Private service As IWindowsFormsEditorService
    70.  
    71.     Public Overloads Overrides Function EditValue(ByVal context As ITypeDescriptorContext, ByVal provider As IServiceProvider, ByVal value As Object) As Object
    72.         If (Not context Is Nothing And Not context.Instance Is Nothing And Not provider Is Nothing) Then
    73.             service = CType(provider.GetService(GetType(IWindowsFormsEditorService)), IWindowsFormsEditorService)
    74.             If (Not service Is Nothing) Then
    75.                 ' the Edit method gets the value ByRef,
    76.                 ' and changes it to the new value when user clicks ok
    77.                 ' I don't know why ... but it took me ages to get this part of the project working
    78.                 ' I didn't find how i could change the property in the propertybag ...
    79.                 ' until i found out that i just needed to change "value" to the new version
    80.                 fEditorLongString.Edit(CType(value, MultiLineString), "Edit " & context.PropertyDescriptor.Name)
    81.             End If
    82.         End If
    83.         Return value
    84.     End Function
    85.  
    86.     Public Overloads Overrides Function GetEditStyle(ByVal context As ITypeDescriptorContext) As UITypeEditorEditStyle
    87.         If (Not context Is Nothing And Not context.Instance Is Nothing) Then
    88.             ' we'll show a modal form
    89.             Return UITypeEditorEditStyle.Modal
    90.         End If
    91.         Return MyBase.GetEditStyle(context)
    92.     End Function
    93. End Class
    chilling

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

    Re: multiline text in propertyGrid?

    You do realize that MrPolites last post was from 1.5 years ago.
    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

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