Database
  Home arrow Database arrow Page 4 - Working With ADOX and Combo Box Control
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE

Working With ADOX and Combo Box Control
By: Mohammed Qattan
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2004-09-21

    Table of Contents:
  • Working With ADOX and Combo Box Control
  • Code
  • Using Combo Box Control
  • Employee Form
  • More on Combo Box

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Working With ADOX and Combo Box Control - Employee Form


    (Page 4 of 5 )

    So let's discuss the form, Employees Information. When this form is first loaded, the “cboEmployees” combo will be loaded with the employees who works in the department.

    At the old days we used to add an item to the Combo Box where we had the String that will be displayed in the Combo Box, and the other is the value in that item, where we used to be bounded to the only data type, Integer.

    Things have changed; now we can bound the Combo Box to a collection, and this collection will fill the Combo Box without writing a lot of for loops, creating and destroying objects.

    When the user selects an item, there is no need to fetch it from the database since we only have its ID.

    So let's do the “FillEmployeesCombo” Sub in more details:

    Private Sub FillEmployeesCombo()
            Dim oDepartment As Department
            Try
                oDepartment = New Department()
                'Bind the combo box to the to the Employees in the

    department
                With cboEmployees
                    .DataSource = oDepartment.Employees
                    .DisplayMember = "Name"
                    'Select the first Employee in the combobox if

    there is any
                    If .Items.Count > 0 Then
                        .SelectedIndex = 0
                    End If
                End With
            Catch oException As Exception
                'Handle the Exception here
                MessageBox.Show(oException.ToString)
            End Try
        End Sub

    1) We first created a Department object, in which we have Employees Collection, which is a collection of all the employees who works in that department.

    We need to bind the Combo Box control to the Employees Collection. Easy as 1,2,3.

    cboEmployees.DataSource = oDepartment.Employees

    2) So far so good, but hey, if we bounded to a collection, and each employee has a “Name” and a “Salary”, what would be displayed in the combo box? Yes, we have to specify the property which the Combo Box will be displaying.

    cboEmployees.DisplayMember = "Name"

    What we did was specify the property name as string; in other words, we told the Combo Box that the collection of object it is binding to has a property called “Name” and that we want to use it to display each item in the Combo Box.

    3) Finally, if there are some employees in the department, then we want to select the first item.

                    If cboEmployees.Items.Count > 0 Then
                        cboEmployees.SelectedIndex = 0
                    End If

    More Database Articles
    More By Mohammed Qattan


     

    DATABASE ARTICLES

    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client
    - ADO`s Stream Object
    - Opening a Record Object Referencing an Open ...
    - Introducing Jasper (SQL Anywhere 10 Beta)
    - Creating a Database Project in VS 2005
    - Manipulating ADO Recordsets





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway