Setting drawing properties with a ComboBox

Discussion in 'AutoCAD' started by Ray Feiler, Feb 1, 2005.

  1. Ray Feiler

    Ray Feiler Guest

    I am using the following code to set a custom drawing property in ACAD 2005
    using a ComboBox and DropDown list. The code works fine except for when you
    type in a value that is not in the list. Any help will be much appreciated.

    Style = 0-fmStyleDropDownCombo
    Locked = False

    Private Sub ComboBox2_Click()

    Dim Key1 As String
    Dim Value1 As String

    Dim CustomPropertyLine As String
    Dim PropertyLineValue As String

    ComboBox2.DropDown

    ' Set value for Line
    CustomPropertyLine = "Line"
    ThisDrawing.SummaryInfo.GetCustomByIndex 1, Key1, Value1
    ThisDrawing.SummaryInfo.SetCustomByIndex 1, CustomPropertyLine,
    ComboBox2.Value

    End Sub

    Private Sub UserForm_Initialize()

    ComboBox2.AddItem "LINE1"
    ComboBox2.AddItem "LINE2"
    ComboBox2.AddItem "LINE3"
     
    Ray Feiler, Feb 1, 2005
    #1
  2. Have you tried using the ComboBox2_Change Method?
     
    Allen Johnson, Feb 1, 2005
    #2
  3. Ray Feiler

    Ray Feiler Guest

    No, and in the help file I can only find information on the Add Method. How
    would I use the Change Method to get the value for what is type in the
    ComboBox by the user and pass it to ComboBox2.Value?
     
    Ray Feiler, Feb 1, 2005
    #3
  4. Hi Ray,

    If you use a list box the user cannot type data into it, only select from
    the values you load into it.

    --

    Regards,


    Laurie Comerford
    www.cadapps.com.au
     
    Laurie Comerford, Feb 1, 2005
    #4
  5. Ray Feiler

    Ray Feiler Guest

    I want the user to be able to type in the value if it is not in the list.
    What is happening when I run my code you can type in the value but it does
    not get passed to ComboBox2.Value. I have set Style = 0-fmStyleDropDownCombo
    and Locked = False but it still does not work.
     
    Ray Feiler, Feb 1, 2005
    #5
  6. Change Private Sub ComboBox2_Click()
    to Private Sub ComboBox2_Change()
     
    Nathan Taylor, Feb 1, 2005
    #6
  7. Ray Feiler

    Ray Feiler Guest

    Thank you very much Nathan. That did exactly what I needed.
    If it isn't too much trouble to ask I have one more problem with this code
    that I have not been able to solve. How can I get the current values for the
    custom properties to display in the ComboBox?
     
    Ray Feiler, Feb 2, 2005
    #7
  8. Ray Feiler

    Ray Feiler Guest

    Here is what I came up with on my own. I'm not sure if it is the best method
    though.

    Dim Key1 As String
    Dim Value1 As String
    Dim CustomPropertyLine As String
    Dim PropertyLineValue As String
    Dim LineIndex As String

    ' Get value for Line
    CustomPropertyLine = "Line"
    ThisDrawing.SummaryInfo.GetCustomByIndex 1, Key1, Value1
    If Value1 = "Line1" Then
    LineIndex = "0"
    ElseIf Value1 = "Line2" Then
    LineIndex = "1"
    Else: LineIndex = "2"
    End If

    ComboBox2.AddItem "Line1" 'ListIndex = 0
    ComboBox2.AddItem "Line2" 'ListIndex = 1
    ComboBox2.AddItem "Line3" 'ListIndex = 2
     
    Ray Feiler, Feb 2, 2005
    #8
  9. Ray Feiler

    Ray Feiler Guest

    This works better. Less code because you do not need to index everything.

    Dim Key1 As String
    Dim Value1 As String
    Dim CustomPropertyLine As String
    Dim PropertyLineValue As String
    ' Get value for Line
    CustomPropertyLine = "Line"
    ThisDrawing.SummaryInfo.GetCustomByIndex 1, Key1, Value1
    ComboBox2.AddItem Value1
    ComboBox2.AddItem "Line1"
    ComboBox2.AddItem "Line2"
    ComboBox2.AddItem "Line3"
    ComboBox2.ListIndex = 0
     
    Ray Feiler, Feb 2, 2005
    #9
  10. Ray Feiler

    Ray Feiler Guest

    I cleaned it up some more.

    Dim Key1 As String
    Dim Value1 As String
    ' Get current value for custom property Line
    ThisDrawing.SummaryInfo.GetCustomByIndex 1, Key1, Value1
    ComboBox2.AddItem Value1
    ComboBox2.AddItem "Line1"
    ComboBox2.AddItem "Line2"
    ComboBox2.AddItem "Line3"
    ComboBox2.ListIndex = 0
     
    Ray Feiler, Feb 3, 2005
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.