tags:

views:

31

answers:

2

Possible Duplicate:
Drop Down in VB.NET

Dear All,

I have a small requirement and that is:

There are two combo boxes on a form and for populating the employee names and roles. I am populating the combo boxes as follows:

  1. I have created a class called "DbConnect" and in that there are 02 functions as:

Public Function getEmployees() As DataTable Dim employeeDS As New DataSet Dim employeeDA As New SqlDataAdapter("prc_emp_list", conn) employeeDA.Fill(employeeDS, "employees") Return employeeDS.Tables("employees") End Function

Public Function getRoles() As DataTable Dim roleDS As New DataSet Dim roleDA As New SqlDataAdapter("prc_role_list", conn) roleDA.Fill(roleDS, "roles") Return roleDS.Tables("roles") End Function

  1. Have designed a form with two combo boxes and am populating data into them as:

Public Sub employees() accessFunction.Open() cboEmployees.DataSource = accessFunction.getEmployees cboEmployees.DisplayMember = "emp_name" cboEmployees.ValueMember = "login_id" End Sub

Public Sub roles() accessFunction.Open() cboRoles.DataSource = accessFunction.getRoles cboRoles.DisplayMember = "role_name" cboRoles.ValueMember = "role_id" End Sub

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load employees() roles() End Sub

THE DATA IS GETTING POPULATED INTO THE COMBO BOXES CORRECTLY AND MY REQUIREMENT IS THAT WHEN I SELECT AN EMPLOYEE FROM THE FIRST COMBO, HIS CORRESPONDING ROLE SHOULD GET SELECTED/DISPLAYED IN THE SECOND COMBO.

Anyone, please help me on this requirement.

Regards, George

A: 

Generally speaking, assuming the comboboxes are successfully populated, you'll need to add an event handler to the Employee combobox to catch changes to the selected item. In that handler, set the Role combobox's selected item to the employee's role.

Of course, you'll need to be holding the mapping of roles to employees to do that.

The implementation details are left as an exercise to the student / someone who knows VB from memory better than I do / someone with more time on their hands / not on a netbook. :)

djacobson
A: 

Simply double click the "Employees" combobox, which will create a new sub that handles changing the selected item there. In that sub, write the code that will populate the "Roles" combobox with the right Roles. It's going to look almost the same as the one you already have, only the select statement is going to look different.

Something like:

    dim cmd as sqlcommand = new sqlcommand _
("Select * from Roles where EmployeeID = " & EmployeesCombobox.selectedValue & ";")

And then, simply bind it to the "Roles" combobox, and it's done.

Ansari