CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2008
    Posts
    15

    Cascading comboboxes inside a datagridview!

    Hi!
    I have a problem with cascading comboboxes inside a datagridview. I have a DataGridView which contains the columns of a table from a MySql database. Some of these columns are foreign keys, and these foreign keys are defined as ComboBox-es that take the values from the parent table.
    I'm posting two pictures with my forms to make it easier:

    This is the table 1, where a user can insert the some data. The two marked columns are the important ones. You can see here that the user entered the values for the Process Step Number and for the Process Step Name. Now, to the Process Step Number 10 it corresponds “proc1”, to 20 it corresponds “proc4” and so on:


    In the second table you can see that there are 2 comboboxes of those columns, which are linked to the first table, displaying the values that have been already saved in the 1’st table:


    Now the important thing is when the user selects a Process Step Number from the combobox, in the Process Step Name combobox should appear directly the process that corresponds to that certain Process Step Number, without the user going through the entire Process Step Name list and selecting the proper one. For example if the user chooses process 34 automatically in the Process Step Name combobox should appear only “p12” (because this process was assigned to the process step number 34 in the table 1).

    Can someone give me some code examples to make the Process step name combobox display only the value that corresponds to the Process Step Number from the first tabel?

    thank you!
    Last edited by Sh_oK; July 1st, 2008 at 11:06 AM.

  2. #2
    Join Date
    Dec 2003
    Location
    Northern Ireland
    Posts
    1,362

    Re: Cascading comboboxes inside a datagridview!

    I don't think I fully understand your problem.

    Do you want to filter the contents of the process step name combo boxes in your second grid depending on which process step number is picked?
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook


    0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010

  3. #3
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Cascading comboboxes inside a datagridview!

    what youneed to do here is set the columb "Process name"'s editable property to false. so the user cannot change it..

    then in your code, when the user selects the "process code" you set the name to the correct value ...

    Gremmy..
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  4. #4
    Join Date
    Jul 2008
    Posts
    15

    Re: Cascading comboboxes inside a datagridview!

    Quote Originally Posted by HairyMonkeyMan
    I don't think I fully understand your problem.

    Do you want to filter the contents of the process step name combo boxes in your second grid depending on which process step number is picked?
    Yes, HairyMonkeyMan. It's a cascading comboboxes inside a datagridview problem.

    GremlinSA, how do i set the process name to the correct value after i set the editable property to false? Can you give me an example of the code?

    Thanks

  5. #5
    Join Date
    Sep 2006
    Posts
    96

    Re: Cascading comboboxes inside a datagridview!

    Sh_ok, you can do this thing so easly if you have set DataSource Property of the ComboBox to a Bindable Datasource.

    Once you set the DataSource Property there have two important properties
    1) ValueMember
    2) DisplayMemeber

    Listen your Datasource should provide two fields, and here it is Process Setp Number, Process Step Name

    In your First ComboboxColumn you Set DisplayMemeber and ValueMember to Process Step Number

    In your Second ComboBoxColumn you Set ValueMember to Process Step Number and DisplayMember to Process Step Name

    Now the CellValueChanged event of column process step number set the SelectedValue of Second combo box to the first combo box selectedvalue

    Hope this will solve your problem

    Warun

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured