rbulph Posted September 11, 2006 Posted September 11, 2006 This article says to use the StringConverter to provide for a drop down list for a property in the property grid. Two questions: 1. Why does it need to be the StringConverter? The TypeConverter class seems to do the job equally well, and 2. Is it possible to make the drop down list multi-select? Quote
Leaders snarfblam Posted September 11, 2006 Leaders Posted September 11, 2006 (1) I've seen tutorials that use TypeConverters, so I don't really know if there is any real advantage to using stringConverters. (2) I'm nearly positive that the property grid doesn't come with this feature out of the box. You'll notice that no simple dropdowns in VS allow you to select multiple enum members. Those properties where you can select multiple enum members (for example, the anchor property of a control) use custom editors. It would be nice if there were built in support for something like an enum dropdown list with checkboxes. Quote [sIGPIC]e[/sIGPIC]
Administrators PlausiblyDamp Posted September 11, 2006 Administrators Posted September 11, 2006 http://www.xtremedotnettalk.com/showthread.php?t=93547 Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
rbulph Posted September 11, 2006 Author Posted September 11, 2006 Thanks, I'll look into that. I wonder why the poster appears to have been banned? I hope there's nothing malicious in the code. Quote
Leaders snarfblam Posted September 11, 2006 Leaders Posted September 11, 2006 JoeMamma wasn't banned because he posted malicious code (in fact, he posted plenty of good code), he was banned because he had a malicious mouth. Quote [sIGPIC]e[/sIGPIC]
rbulph Posted September 13, 2006 Author Posted September 13, 2006 This is easy once you know how. Define your property with the attribute as follows: <Editor(GetType(CustomEditor)> Public Property MyStringProp as String... Then define your editor class: Public Class CustomEditor Inherits System.Drawing.Design.UITypeEditor Public Overrides Function GetEditStyle(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle Return Drawing.Design.UITypeEditorEditStyle.DropDown End Function Public Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object Dim ui As New System.Windows.Forms.CheckedListBox ui.Items.Add("ABC") ui.Items.Add("DEF") ui.Items.Add("GHI") ui.CheckOnClick = True ui.BorderStyle = Windows.Forms.BorderStyle.None Dim I As MyClass = context.Instance If I.MyStringProp <> "" Then Dim f() As String = I.MyStringProp.Split(",") For Each s As String In f If ui.Items.IndexOf(s) <> -1 Then ui.SetItemChecked(ui.Items.IndexOf(s), True) Next End If Dim fr As System.Windows.Forms.Design.IWindowsFormsEditorService = provider.GetService(GetType(System.Windows.Forms.Design.IWindowsFormsEditorService)) fr.DropDownControl(ui) Dim s2 As String For Each s3 As String In ui.CheckedItems s2 = s2 & s3 & "," Next If Right$(s2, 1) = "," Then s2 = Left$(s2, Len(s2) - 1) ui.Dispose() Return MyBase.EditValue(context, provider, s2) End Function End Class Obviously this code can be tidied up a little. Query whether I'm getting hold of the SelectedObject in the right way in using context.Instance. value always seems to be Nothing so I can't use that. Quote
rbulph Posted October 13, 2006 Author Posted October 13, 2006 If anyone does investigate this further, I'd love to know how you control whether the custom drop down extends all the way across the values column. Currently it always extends at least this far, but that's not very good where the dropdown is a non-resizeable control like the monthview. You get a lot of unnecessary white space surrounding the control when there's more room than is necessary. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.