<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Trouble populating a ComboBox in a VB.NET Windows Form in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/trouble-populating-a-combobox-in-a-vb-net-windows-form/m-p/11416929#M11676</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try setting the selected index:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;cboSelCust.SelectedIndex = 1&lt;/LI-CODE&gt;
&lt;P&gt;You should also pay attention to the &lt;A href="https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.combobox.dropdownstyle?view=windowsdesktop-6.0#system-windows-forms-combobox-dropdownstyle" target="_blank" rel="noopener"&gt;ComboBox.DropDownStyle&lt;/A&gt;, it should be &lt;A href="https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.comboboxstyle?view=windowsdesktop-6.0" target="_blank" rel="noopener"&gt;ComboBoxStyle.DropDownList&lt;/A&gt; if you do not want an editable text portion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Sep 2022 21:18:01 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2022-09-12T21:18:01Z</dc:date>
    <item>
      <title>Trouble populating a ComboBox in a VB.NET Windows Form</title>
      <link>https://forums.autodesk.com/t5/net-forum/trouble-populating-a-combobox-in-a-vb-net-windows-form/m-p/11416886#M11675</link>
      <description>&lt;P&gt;Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am developing a VB.NET add-in (DLL) for AutoCAD.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a Windows Form with a ComboBox on it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For debugging purposes, I have manually added items to the ComboBox within the main subroutine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;cboSelCust.Clear
cboSelCust.Items.Add("ABC")
cboSelCust.Items.Add("DEF")&lt;/LI-CODE&gt;&lt;P&gt;During debugging, the ComboBox shows that it has two items:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2022-09-12_15-35-04.png" style="width: 501px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1114832iDDB683AA39492F44/image-size/medium?v=v2&amp;amp;px=400" role="button" title="2022-09-12_15-35-04.png" alt="2022-09-12_15-35-04.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;However, when I show the dialog box,&lt;/P&gt;&lt;LI-CODE lang="general"&gt;' Declare form and show it
Dim myForm As New MainForm
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(myForm)&lt;/LI-CODE&gt;&lt;P&gt;the ComboBox is empty.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2022-09-12_15-31-50.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1114833iF420E2DCA25C5055/image-size/medium?v=v2&amp;amp;px=400" role="button" title="2022-09-12_15-31-50.png" alt="2022-09-12_15-31-50.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope it is something simple that I have overlooked to get the names to show in the ComboBox.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your time and attention. I look forward to your replies.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jerry&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 20:46:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/trouble-populating-a-combobox-in-a-vb-net-windows-form/m-p/11416886#M11675</guid>
      <dc:creator>JBerns</dc:creator>
      <dc:date>2022-09-12T20:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble populating a ComboBox in a VB.NET Windows Form</title>
      <link>https://forums.autodesk.com/t5/net-forum/trouble-populating-a-combobox-in-a-vb-net-windows-form/m-p/11416929#M11676</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try setting the selected index:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;cboSelCust.SelectedIndex = 1&lt;/LI-CODE&gt;
&lt;P&gt;You should also pay attention to the &lt;A href="https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.combobox.dropdownstyle?view=windowsdesktop-6.0#system-windows-forms-combobox-dropdownstyle" target="_blank" rel="noopener"&gt;ComboBox.DropDownStyle&lt;/A&gt;, it should be &lt;A href="https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.comboboxstyle?view=windowsdesktop-6.0" target="_blank" rel="noopener"&gt;ComboBoxStyle.DropDownList&lt;/A&gt; if you do not want an editable text portion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 21:18:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/trouble-populating-a-combobox-in-a-vb-net-windows-form/m-p/11416929#M11676</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-09-12T21:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble populating a ComboBox in a VB.NET Windows Form</title>
      <link>https://forums.autodesk.com/t5/net-forum/trouble-populating-a-combobox-in-a-vb-net-windows-form/m-p/11417021#M11677</link>
      <description>&lt;P&gt;Where these lines of code runs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;cboSelCust.Clear
cboSelCust.Items.Add("ABC")
cboSelCust.Items.Add("DEF")&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is, you'd better show more code where above lines are included.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, where "Select a customer" comes from in the combobox? If it is not entered by you after the form shows), then you must have code somewhere does that, which replaces your hard-coded 2 items in the combo box. So, you really examine your code carefully, or post all the code related to the form being populated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 22:27:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/trouble-populating-a-combobox-in-a-vb-net-windows-form/m-p/11417021#M11677</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2022-09-12T22:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble populating a ComboBox in a VB.NET Windows Form</title>
      <link>https://forums.autodesk.com/t5/net-forum/trouble-populating-a-combobox-in-a-vb-net-windows-form/m-p/11418341#M11678</link>
      <description>&lt;P&gt;The majority of my code is functioning correctly, so I did not post all of it.&lt;/P&gt;&lt;P&gt;After posting this message, I did some more testing.&lt;/P&gt;&lt;P&gt;I double-clicked the form which created the MainForm_Load function. I thought the form was being initialized and loaded, but apparently not.&lt;/P&gt;&lt;P&gt;After placing this line of code:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;cboSelCust.DataSource = lstCustomernames&lt;/LI-CODE&gt;&lt;P&gt;in the MainForm_Load, the ComboBox list was populated as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So my confusion is then how to create a user defined command (PDF_DXF2) and then open the dialog box when the command starts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If it is of benefit, I will show the condensed version of the code I have so far, which is now working, but I am not sure if I am initializing and loading correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports System.Windows.Forms
Imports System.Data.OleDb
Imports System.Data.Sql
Imports System.Data
Imports System.Data.SqlClient
Imports System.DateTime
Imports System.Drawing
Imports System.IO

Public Class MainForm

	Public strCustomerName As String
	Private lstCustomernames As New List(Of String)

	&amp;lt;CommandMethod("PDF_DXF2")&amp;gt;
	Public Sub IntializeUserForm()
		' Declare form and show it
		Dim myForm As New MainForm
		Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(myForm)
	End Sub

	Function GetPNCatalogs() As String
		' Returns a string, such as "ProNest14"
        	' This code is working
	End Function

	Sub GetCustomerNamesFromSql()
		' Declare the ProNest catalog name as a string
		Dim PNcatalog As String
		' Get the largest catalog from the ProNest database on the ENG server
		PNcatalog = GetPNCatalogs()
		' Gets customer names from a SQL database and stores the names in a List(of Strings) variable
        	'This code is working
	End Sub

	Private Sub BtnContinue_Click(sender As Object, e As EventArgs) Handles btnContinue.Click
		MsgBox("You selected the Continue button.")
	End Sub

	Private Sub BtnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
		MsgBox("You selected the Cancel button.")
		Me.Close()
	End Sub


	Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
		' Get Customer data from SQL database
		GetCustomerNamesFromSql()

		' Assign customer names to ComboBox
		cboSelCust.DataSource = lstCustomernames

	End Sub

End Class&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you need to see the full VS project files, I can provide it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all for your feedback.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jerry&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 13:35:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/trouble-populating-a-combobox-in-a-vb-net-windows-form/m-p/11418341#M11678</guid>
      <dc:creator>JBerns</dc:creator>
      <dc:date>2022-09-13T13:35:02Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble populating a ComboBox in a VB.NET Windows Form</title>
      <link>https://forums.autodesk.com/t5/net-forum/trouble-populating-a-combobox-in-a-vb-net-windows-form/m-p/11420871#M11679</link>
      <description>&lt;P&gt;In your basic showing UI case, the rule of thumb is to separate the UI code (i.e. class MainForm here) from AutoCAD operation: the form should no nothing about whether it is called from AutoCAD or not. So, you do not put &amp;lt;CommandMethod&amp;gt; in the form class.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I usually structure my simple Acad plugin in this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;MyCommands.cls&lt;/STRONG&gt; - which is decorated with &amp;lt;Assembly: CommandClass()&amp;gt; and contains all methods decorated by &amp;lt;CommandMethod()&amp;gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A few classes for specific AutoCAD operations, such as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;TitleBlockUpdate.cls&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;PdfCreation.cls&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then most likely one or more common utility classes&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;CadUtilities.cls&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then the UI classes&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;MainForm.cls&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;TitleBlockForm.cls&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;PdfOutputForm.cls&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the operations run from MyCommands.cls:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;CommandMethod("TitleBlock"&amp;gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Public Shared Sub DoTitleBlock()&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Dim tb As New TitleBlockUpdate()&lt;/P&gt;
&lt;P&gt;&amp;nbsp; tb.DoWork() '' Which could show its own UI&lt;/P&gt;
&lt;P&gt;End Sub&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;CommandMethod("MyPdf")&amp;gt;&lt;/P&gt;
&lt;P&gt;Public Shared Sub CreatePdfForClient()&lt;/P&gt;
&lt;P&gt;&amp;nbsp; '' Get client name from MainForm&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Dim clientName As String&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Using frm As MainForm = New MainForm()&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;If Application.ShowModalDialog(frm)==DialogResult.OK Then&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;clientName=frm.SelectedCleint&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;End If&lt;/P&gt;
&lt;P&gt;&amp;nbsp; End Using&lt;/P&gt;
&lt;P&gt;&amp;nbsp; If String.IsNullOrEmpty(clientName) Then Exit Sub&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;'' Assume the PdfCreation class requires a client name in its constructor&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Dim pdtTool As New PdfCreation(clientName)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;'' inside this process, more UIs can be showed up, but the MyCommands class does not need to know&lt;/P&gt;
&lt;P&gt;&amp;nbsp; pdfTool.CreatePdfSet()&amp;nbsp;&lt;/P&gt;
&lt;P&gt;End Sub&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;CommandMethod("xxxxx")&amp;gt;&lt;/P&gt;
&lt;P&gt;Public Shared Sub XXXXXXX()&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ... ...&lt;/P&gt;
&lt;P&gt;End Sub&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see, each class does its own work and the MyCommands.cls is like a "switch board" to start each operation as a command by newing operation class and calling its exposed public method, but it does not need to know what the operation classes do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this gives some ideas.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 14:10:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/trouble-populating-a-combobox-in-a-vb-net-windows-form/m-p/11420871#M11679</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2022-09-14T14:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble populating a ComboBox in a VB.NET Windows Form</title>
      <link>https://forums.autodesk.com/t5/net-forum/trouble-populating-a-combobox-in-a-vb-net-windows-form/m-p/11421183#M11680</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you both for the information you provided. I hope to understand it more as I continue to learn AutoCAD .NET add-in development.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jerry&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 16:02:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/trouble-populating-a-combobox-in-a-vb-net-windows-form/m-p/11421183#M11680</guid>
      <dc:creator>JBerns</dc:creator>
      <dc:date>2022-09-14T16:02:14Z</dc:date>
    </item>
  </channel>
</rss>

