locked
Multiple Combo Boxes in a Data Grid - - vb.net RRS feed

  • Question

  • I want to use multiple combo boxes to display data in a data Grid view. I already have the data grid view working using one combo box passing one parameter. However, I am thinking the SQL statement has to use if then logic in case one the combo boxes is not used.


    Problem : I can't get the if then else statement to work in SQL? Does anybody have a solution for this? Do i need to create a stored procedure to do this? If so how do you bind that to a data grid?

    Thanks,  Your help is appreciated.
    • Moved by Zhi-Xin Ye Tuesday, April 21, 2009 3:22 PM not a BCL question
    Tuesday, April 14, 2009 5:35 PM

Answers

  • I assume you should be able to set .visible of combobox (using conditional "If") to false on ItemBound. Also there are couple of good links on DataGrid and ComboBox:
    http://it.toolbox.com/wiki/index.php/About_Combobox_in_DataGrid_(.NET_framework)
    http://www.xmlfox.com/datagrid_combobox.htm
    • Marked as answer by Rabbitholes Tuesday, May 26, 2009 10:01 PM
    Wednesday, April 15, 2009 11:46 PM

All replies

  • Lets say if you have a Country field in the database  and you have corresponding combobox cmbCountry
    Assign @country to "0" if nothing is selected (@country is commandparameter). You can write your Sql something like this:
    "
    Where
    and (@country ='0' Or (@country <>'0' And countryID = @country))

    "
    Wednesday, April 15, 2009 3:42 AM
  • Thanks, How about if I have Multiple combo boxes.....

     Ex: cmbCountry cmbState cmbCity

     How would I go about getting only 2 of the combo boxes to be displayed in the Data Grid. I want cmbCountry and cmbState displayed, but not cmbCity. I am assuming I have to use an "if" statement.  I wouldn't want to display the cmbCity because it doesn't have any data.


       If you can help with that much it would be great.


    I resolved this issue by hard coding multiple SQL in the form .vb using if statements and multiple select statements based on if the combo boxes were populated withdata or not.

    I think there is better solution, but thats what I did.


    Any help or insight would be greatly appreciated, thanks.
    Wednesday, April 15, 2009 9:29 PM
  • I assume you should be able to set .visible of combobox (using conditional "If") to false on ItemBound. Also there are couple of good links on DataGrid and ComboBox:
    http://it.toolbox.com/wiki/index.php/About_Combobox_in_DataGrid_(.NET_framework)
    http://www.xmlfox.com/datagrid_combobox.htm
    • Marked as answer by Rabbitholes Tuesday, May 26, 2009 10:01 PM
    Wednesday, April 15, 2009 11:46 PM