Click here to Skip to main content
16,017,376 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Visual studio creating automatically Form pro edit, delete and add row in DataTable (creating ToolBar with buttons Add, Delete, Update and Form with controls for editing, viewing data in DataTable. But, I do not find way, how to modify code for adding new row to DataTable, so that the user can not insert data into a form that is already contained.

Example: First control is ComboBox - User. This control is used for entering Name User (over his ID). Second control is ComboBox - Car. This control is used for entering car (over his ID) for business trip. How do I make the content control ComboBox - Car (and code for filtering data only during add new row to DataTable) that in ComboBox - Car not offered values which are already stored in the DataTable? (Example User with Id=1 use Car with Id=1, so ComboBox - Car do not have value 1, if I am change User to Id=2, ComboBox - Car refresh content and has only values, which will not duplicity rows in DataTable for user with Id=2).

I will be grateful for any tip or help.

Jaroslav
Posted

While binding data table to combo box check weather the data table has those values or not.
 
Share this answer
 
While Binding do something like - dataTable.Select("ID <>" carIDOfTheUser.ToString()). This will return a datarow array. You can convert and create a datasource.Similarly you can create a dataview from the datatable based on the select condition.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900