We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

parent-child combo box cells in a GridDataBoundGrid

Hi, just curious if it''s possible to have one combo box cell filter a second combo box cell on the same row in a GridDataBoundGrid. I tried to set it up as you would with 2 regular combo box controls, and it doesn''t seem to work. I keep getting a "Value does not fall within the expected range error" when trying to tab out of the 1st combo box after making a selection. I''m trapped there unless I hit ESC and undo the selection. Here''s a code sample: Dim dtType As DataTable = colData.Tables("MedicationType") Dim dtMed As DataTable = colData.Tables("Medication") Dim drRelation As DataRelation = New DataRelation("dr1", dtType.Columns("id"), dtMed.Columns("treatmentType")) colData.Relations.Add(drRelation) Dim col As GridBoundColumn = Me.bdgMedicationType With col.StyleInfo .DataSource = colData .DisplayMember = "MedicationType.name" .ValueMember = "MedicationType.id" End With col = Me.bdgMedicationMed With col.StyleInfo .DataSource = colData .DisplayMember = "MedicationType.dr1.name" .ValueMember = "MedicationType.dr1.id" End With * Basically, I''ve got a medication type dropdown I want users to select, and after they do I want to show the medications for that type in the 2nd dropdown.

10 Replies

JD James Donnelly September 14, 2005 01:23 AM UTC

Actually, I just noticed that when I ESC out from the error message, and clear the 1st combo box selection, the options for the 2nd combo box do actually reflect the selection I made in the 1st combo box that was cleared out. So the relation seems to be working in filtering the 2nd combo box list, but it won''t let me leave the 1st combo box after making a selection. Weird.


JD James Donnelly September 14, 2005 01:49 AM UTC

Also, when entering the user screen, if I just try to make a selection from the 2nd combo box, ignoring the 1st combo box, it''s giving me an error that it can''t write a string to Int16. That seems to suggest to me that the ValueMember isn''t working and it''s trying to pass the text value to the DataTable instead (as a backup or error catch of some kind if there''s a problem with the ValueMember). I don''t know. Sure would like to be able to do this though, without having to code it manually.


JD James Donnelly September 14, 2005 02:08 AM UTC

I did find an example of how to do this here: http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=115 But is there any reason why a DataRelation won''t work, or am I just doing it wrong? Please let me know. If a DataRelation won''t work, I won''t waste my time, but it would be better for my UI engine if it did (my UI engine handles all the binding through tagging and metadata, so I can identify data relations in the metadata and instruct the logic to set up the relation automatically - otherwise I have to manually code which I copiously try to avoid).


JD James Donnelly September 14, 2005 02:11 AM UTC

Sorry, I seem to be having a conversation on my own. Let me summarize: 1. The DataRelation works in filtering the 2nd combobox list with the selection from the 1st combobox, but neither combo box seems to work in passing the ValueMember data to the DataTable (seems to be sending the text value of the combobox instead). 2. I realize that it can be done a different way, with manual coding, but just want to know if it''s possible with a DataRelation, and hopefully I''m just doing it wrong. >I did find an example of how to do this here: > >http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=115 > >But is there any reason why a DataRelation won''t work, or am I just doing it wrong? > >Please let me know. If a DataRelation won''t work, I won''t waste my time, but it would be better for my UI engine if it did (my UI engine handles all the binding through tagging and metadata, so I can identify data relations in the metadata and instruct the logic to set up the relation automatically - otherwise I have to manually code which I copiously try to avoid).


JD James Donnelly September 14, 2005 02:28 AM UTC

Two more updates to this: One, I mistakenly had the 2nd combo box set to Editable, so when I changed it to Exclusive, I get the same error as the 1st combo box (if editing 2nd combo box first), which is "value not in expected range". Two, oddly enough my example works if I change both the value and display member to show the ID instead of the name (not as functional obviously, but just testing it). So, hopefully I didn''t confuse the issue earlier by being set to Editable. The problem is clearly related to a string value tripping something up when you try to exit the combobox cell, but if you''re just using number values, using a DataRelation as I showed in the code above works fine.


JD James Donnelly September 14, 2005 03:33 AM UTC

Okay, I almost got it now, by changing to code to this (selection on 1st combobox works, and filters the list of the 2nd combobox, but still get error trying to leave 2nd combobox after selection): Dim dtType As DataTable = colData.Tables("MedicationType") Dim dtMed As DataTable = colData.Tables("Medication") Dim drRelation As DataRelation drRelation = New DataRelation("dr1", dtType.Columns("id"), dtMed.Columns("treatmentType")) colData.Relations.Add(drRelation) Dim col As GridBoundColumn = Me.bdgMedicationType With col.StyleInfo .DataSource = dtType .DisplayMember = "name" .ValueMember = "id" End With Dim col2 As GridBoundColumn = Me.bdgMedicationMed With col2.StyleInfo .DataSource = dtType .DisplayMember = "dr1.name" .ValueMember = "dr1.id" End With


JD James Donnelly September 14, 2005 03:46 AM UTC

Okay, I figured it out. The GridDataBoundGrid doesn''t support prefixing in the ValueMember and DisplayMember properties. I tested it out without a DataRelation. I''ll have to do it manually. Unless, is there some way I can handle that error (the one that says "value does not fall within the expected range")?


AD Administrator Syncfusion Team September 14, 2005 03:00 PM UTC

Hi Jonnes Sorry for the delay. The error is about the validation. You can follow this KB on how to handle the Currentcellvalidation event and to catch the error message and to cancel it. KB link: http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=26 Best Regards Mouli


JD James Donnelly September 14, 2005 07:20 PM UTC

Mouli, The error occurs with or without a data relation. It''s not even related to the above. The error occurs if you use "datatable.datacolumn" format for ValueMember and DisplayMember (with the data source set to the dataset) rather than "datacolumn" format (with the data source set to the datatable). All .NET code I''ve seen so far that synchronizes combo boxes with a DataRelation must work by setting the datasource to the dataset, not datatable, and then using the prefix format "datatable.datacolumn" (parent) and "datatable.relation.datacolumn" (child). If the GridDataBoundGrid doesn''t support prefixing in the ValueMember and DisplayMember, you just can''t to what I''m trying to do (the way I''m trying to do it). I''ve replicated the problem with just a single data column that sets the combobox data source using the long format. I doesn''t work.


AD Administrator Syncfusion Team September 15, 2005 03:58 AM UTC

Hi James,, I tried to replicate here but no luck. Can you please send us a sample showing up the issue ? That would be helpful for me to work on it. Regards Mouli

Loader.
Live Chat Icon For mobile
Up arrow icon