DataGridView problem. "corresponding" values

Sh_oK

Member
Joined
Jun 25, 2008
Messages
10
Programming Experience
1-3
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. What I want to do and I don’t know how is to “connect” o selection from one column with another column.
I’m giving an example to be more explicit:
In the parent table t1, I have 2 columns: Process_number and process_name.
Now in the table t2 I have more columns, between whom the two columns from above which are combobox-es and can only take values already existing in those columns from t1 table. Until here everything works fine. Now when I choose a value in the Process_number column from t2 table, I want the value from the column process_number from t2 to be automatically inserted with the corresponding value from the process_number column from t1 .
For example if in t1 I have the following values:
1 in process_number and AAA in process_name
1 in process_number and BBB in process_name
when in table t2 I choose in process_number the value 1, automatically in process_name I want to appear AAA, respectively if I choose 2 to appear BBB.

I hope that I wasn’t too ambiguous and I managed to explain what I need. Any suggestion would be a great help!
Thank you
 
cjard the videos you showed me don't really point to my problem. I can display the values that i want in all the columns, i know how to set the ValueMember and the DisplayMember of the comboboxes to show the values that I want,. What I need is some kind of filter I think…

Let me show you some pictures with my tables, maybe this way everything will be clearer:
This is the table 1, where you can insert the some data. The two marked columns are the important ones. You 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 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).
 
Ahh.. now there's something I've not tried; having cascading comboboxes inside a datagridview. I dont foresee any reason why it wouldnt work like a normal combo box, but as with everything that "should be easy" it usually isnt..

Are you familiar with the process of displaying related data? THere's a section on it in the DW2 link in my sig if not..
 
Yes! finally someone who knows what I’m talking about! :)
Cascading comboboxes inside a datagridview! I've experienced with some methods for normal cascading comboboxes, but inside the datagridview they didn't work.
I’m struggling with this problem for over a week now and i have no idea left.
I read the section about displaying related date from your DW2 link and it seems pretty familiar.
So, some help here would be much appreciated! :)
 
OK, i made a demo project for this yesterday AND... it works but for one flaw, that is never seen when we do not use grids (multiple rows on show at once)

Because all DGV Combos in my example share the same bindingsources, a change to one affects the others. Play with the sample long enough and you'll figure it out. I do fear that you may have to make a separate bindingsource for each row (and i'm not sure how you'd do that, nor have i the time to investigate) or roll your own DataGridViewCombo that takes, as a parameter, another DGVCombo to read the selected value from
 

Attachments

  • CascadingComboInDGV.zip
    24.2 KB · Views: 22
Well, I can tell you that if you put a Citrus Orange in and then on row 2 put a treehanging Banana, that row 1 will flick to a Citrus Coconut.. (Or soemthing like that) I'll leave you to figure out why :)
 

Latest posts

Back
Top