Hack Forums
[.NET] Briefly describe how you would populate a Drop Down List from the contents of a table - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Briefly describe how you would populate a Drop Down List from the contents of a table (/showthread.php?tid=6068222)



Briefly describe how you would populate a Drop Down List from the contents of a table - unknown321 - Apr 17, 2020

Need help with this question: Briefly describe how you would populate a Drop Down List from the contents of a table in a database

Any help is appreciated


RE: Briefly describe how you would populate a Drop Down List from the contents of a table - itcorp - Apr 17, 2020

(Apr 17, 2020 12:58 PM)unknown321 Wrote:  Need help with this question: Briefly describe how you would populate a Drop Down List from the contents of a table in a database

Any help is appreciated

The name of the control "Drop Down List" in the .net is closely related to web technologies while in a desktop environment it is called combobox so I'm not really sure for what technology you're looking for solution.

But regardless,i personally use in most cases Entity Framework as a way to communicate with the database therefore, one way to fill a combo would be

table
Code
USE [hf]
GO

/****** Object:  Table [dbo].[Data]    Script Date: 4/17/2020 10:54:36 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Data](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [Name] [nvarchar](30) NULL
) ON [PRIMARY]
GO

Code
Public Async Sub PopulateCombo(ByVal combo As ComboBox)
       Using db = New hfEntities()
           Dim select= Await (From user In db.Data Select user).ToListAsync()
           combo.ItemsSource = select
           combo.DisplayMemberPath = "Name"
           combo.SelectedValuePath = "ID"
       End Using
   End Sub

the aforementioned way somehow proved to be a solid to load large data in combox but implementation and solution implementation it really depends on your requirements and the amount of data and implementation itself along with what you want to achieve.
Therefore, it would be nice to say something more that you want to achieve in order to find an adequate solution for your problem.All the best buddy