none
how to change the value of combobox

    Question

  • Hi everybody

    I'm have 2 combobox.a Departments combobox  and an position combobox  where one Departments record in the Departments combobox have many position records in the position combobox.

    I want when i choose a Departments in  Departments combobox then all positionin that Departments will display in  position combobox.and i want get the value of the position combobox replace into staff table. i want add Staff_ID and  position of the staff into staff table.

    Help me pls.!!
    Sunday, June 13, 2010 2:49 AM

Answers

  • In the "parent" combobox you would filter the child records that you want in the "child" combobox. I'm too tired to write your code for you right now, but if you look at this example out on MSDN it shows "parent" combobox with "child" grid (except you would have a combobox for the children records, but same  concept, just using rowsource instead of recordsource).

     http://support.microsoft.com/kb/142567

    If you want to get a little more advanced you can use an SQL statement in the child combobox's rowsource property (rowsourcetype=3) and then use the combobox's Requery() method to refresh the child departments that show in the combobox.

    There's a little more to all of this, but if you don't mind putting in a little work this should get you going down the right path.


    Craig S. Boyd
    Sunday, June 13, 2010 4:26 AM
  • Here is a sample:

    Set Textmerge delimiters to '%%','%%'
    Public oForm
    oForm = CreateObject('cmbLinked')
    oForm.Show
    
    Define Class cmbLinked As Form
     DataSession=2
     Height = 70
     Width = 615
     Add Object lblCustomer As Label With Caption="Customer ID:",Left=5,Top=5,Autosize=.t.
     Add Object lblOrders As Label With Caption="Orders:[0]",Left=310,Top=5,AutoSize=.t.
     Add Object cmbCustomer As ComboBox With Left=5,Top=30,Width=300
     Add Object cmbOrders As ComboBox With Left=310,Top=30,Width=300
    
     Procedure Init
      With This.cmbCustomer
       .RowSourceType = 3
       .RowSource = "select company,cust_id from (_samples+'data\customer') into cursor crsMaster"
      Endwith
      With This.cmbOrders
       .RowSourceType = 3
       .RowSource = "select order_id,order_date,cust_id"+;
        " from (_samples+'data\orders')"+;
        " where cust_id = crsMaster.cust_id"+;
        " into cursor cboAlt"
       .ColumnCount = 3
      Endwith
     Endproc
    
     Procedure cmbCustomer.InteractiveChange
     	Local lnOrders
      With This.Parent.cmbOrders
       .ListIndex=0
       .Requery()
       lnOrders = .ListCount
      Endwith
     	this.Parent.lblCustomer.Caption = "Customer ID:"+crsMaster.Cust_id
     	this.Parent.lblOrders.Caption = Textmerge('Orders:[%%m.lnOrders%%]')
     Endproc
    Enddefine

    • Marked as answer by Itachivn Thursday, June 17, 2010 2:24 AM
    Monday, June 14, 2010 2:41 PM

All replies

  • In the "parent" combobox you would filter the child records that you want in the "child" combobox. I'm too tired to write your code for you right now, but if you look at this example out on MSDN it shows "parent" combobox with "child" grid (except you would have a combobox for the children records, but same  concept, just using rowsource instead of recordsource).

     http://support.microsoft.com/kb/142567

    If you want to get a little more advanced you can use an SQL statement in the child combobox's rowsource property (rowsourcetype=3) and then use the combobox's Requery() method to refresh the child departments that show in the combobox.

    There's a little more to all of this, but if you don't mind putting in a little work this should get you going down the right path.


    Craig S. Boyd
    Sunday, June 13, 2010 4:26 AM
  • Here is a sample:

    Set Textmerge delimiters to '%%','%%'
    Public oForm
    oForm = CreateObject('cmbLinked')
    oForm.Show
    
    Define Class cmbLinked As Form
     DataSession=2
     Height = 70
     Width = 615
     Add Object lblCustomer As Label With Caption="Customer ID:",Left=5,Top=5,Autosize=.t.
     Add Object lblOrders As Label With Caption="Orders:[0]",Left=310,Top=5,AutoSize=.t.
     Add Object cmbCustomer As ComboBox With Left=5,Top=30,Width=300
     Add Object cmbOrders As ComboBox With Left=310,Top=30,Width=300
    
     Procedure Init
      With This.cmbCustomer
       .RowSourceType = 3
       .RowSource = "select company,cust_id from (_samples+'data\customer') into cursor crsMaster"
      Endwith
      With This.cmbOrders
       .RowSourceType = 3
       .RowSource = "select order_id,order_date,cust_id"+;
        " from (_samples+'data\orders')"+;
        " where cust_id = crsMaster.cust_id"+;
        " into cursor cboAlt"
       .ColumnCount = 3
      Endwith
     Endproc
    
     Procedure cmbCustomer.InteractiveChange
     	Local lnOrders
      With This.Parent.cmbOrders
       .ListIndex=0
       .Requery()
       lnOrders = .ListCount
      Endwith
     	this.Parent.lblCustomer.Caption = "Customer ID:"+crsMaster.Cust_id
     	this.Parent.lblOrders.Caption = Textmerge('Orders:[%%m.lnOrders%%]')
     Endproc
    Enddefine

    • Marked as answer by Itachivn Thursday, June 17, 2010 2:24 AM
    Monday, June 14, 2010 2:41 PM