Author Topic: Populate listbox at DesignTime  (Read 2727 times)

0 Members and 1 Guest are viewing this topic.

djee

  • Newt
  • Posts: 49
Populate listbox at DesignTime
« on: August 04, 2015, 08:15:20 AM »
i need to populate a ListBox at design time (before my Form appears) with all the existing LayerFilter in the drawing... Anyway to achieve that?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Populate listbox at DesignTime
« Reply #1 on: August 04, 2015, 08:28:37 AM »
No, because at design time, you are not working in the drawing. In order to populate a ListBox with with all of the layer fileters, you must do it at runtime. Look at the form events and select one that happens before or at the time the form is generated.

Of course, now that I think of it, I believe you are confused on the terminology. Design Time is the time when you are writing the code that will ultimately be your application .. before you compile the code. Because things such as layer filters are dynamic, meaning they can and do change between drawings and users can readily add/delete them. Runtime is when the application is executed starting at the first function call at the application entrypoint.

You could add things to the list at design time, but I don't think it would serve your purpose.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

djee

  • Newt
  • Posts: 49
Re: Populate listbox at DesignTime
« Reply #2 on: August 04, 2015, 09:31:26 AM »
Ok thanks for the clarification... I'll try to explain myself better; I'm in an active Autocad drawing, I enter the command line that fire's up my AutoCAD form. When that form appears, I would like my ListBox to display all of the LayerFilter in the drawing (right there without any input of the user)...

djee

  • Newt
  • Posts: 49
Re: Populate listbox at DesignTime
« Reply #3 on: August 04, 2015, 09:49:39 AM »
Here's what I got concerning LayerFilters but my problem is populating my listbox when firing the form.
Code: [Select]
    ' list the existing layer filters
    Public Sub ListLayerFilters(ByVal MyListofLayerFilter As System.Windows.Forms.ListBox)
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor

        ' List the nested layer filters

        Dim lfc As LayerFilterCollection = db.LayerFilters.Root.NestedFilters

        For i As Integer = 0 To lfc.Count - 1
            Dim lf As Autodesk.AutoCAD.LayerManager.LayerFilter = lfc(i)
            MyListofLayerFilter.Items.Add(lf.Name.ToString)
        Next
    End Sub

BlackBox

  • King Gator
  • Posts: 3770
Re: Populate listbox at DesignTime
« Reply #4 on: August 04, 2015, 10:34:07 AM »
Here's what I got concerning LayerFilters but my problem is populating my listbox when firing the form.

Have you tried adding a Form Constructor overload, which accepts a returned List<string> / string[] of layer filters?

Another way, is to instantiate your Form, then for each layer filter, add list item.
"How we think determines what we do, and what we do determines what we get."

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Populate listbox at DesignTime
« Reply #5 on: August 04, 2015, 10:51:07 AM »
Another idea is to populate the listbox during the forms show event.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

djee

  • Newt
  • Posts: 49
Re: Populate listbox at DesignTime
« Reply #6 on: August 04, 2015, 11:26:26 AM »
I guess you mean the "Shown" event...? I don't see the "Show" event in my form...

djee

  • Newt
  • Posts: 49
Re: Populate listbox at DesignTime
« Reply #7 on: August 04, 2015, 11:30:44 AM »
Work Perfect! thanks Keith!! I do feel very stupid right now but hey, you learn something everyday...

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Populate listbox at DesignTime
« Reply #8 on: August 04, 2015, 11:46:05 AM »
Yes, I guess I meant the shown event. 
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Populate listbox at DesignTime
« Reply #9 on: August 05, 2015, 08:01:46 AM »
Step 1: Stop using archaic windows forms
Step 2: Start using WPF and the MVVM pattern
Step 3: Create a ListBox and bind its ItemsSource to Application.UIBindings.Collections.Layers
Done.
Revit 2019, AMEP 2019 64bit Win 10

Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
Re: Populate listbox at DesignTime
« Reply #10 on: August 05, 2015, 02:30:23 PM »
Step 1: Stop using archaic windows forms
Step 2: Start using WPF and the MVVM pattern
Step 3: Create a ListBox and bind its ItemsSource to Application.UIBindings.Collections.Layers
Done.

I've been exploring databindings on a form recently. Is there a good example project that shows what this would look like?

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Populate listbox at DesignTime
« Reply #11 on: August 05, 2015, 02:36:50 PM »
Gile's Converter Palette is an example.


http://www.theswamp.org/index.php?topic=49358.0
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013