Double Click row on table 1 to add data to table 2

DataVisually

New member
Joined
Aug 27, 2020
Messages
2
Programming Experience
Beginner
Hi, I'm just starting my C# journey in more depth and I have something I would like to work on and would appreciate any pointers.

I have an unbound form which has several search boxes in order to show filtered data in a table (from SQL Server). Ideally, I would like one of the two following actions to work:

scenario 1) double clicking on a row in the search results table adds the contents of that row to a second table on the parent form.

scenario 2) a checkbox being ticked with a separate ADD ALL button being clicked to loop through each of the ticked rows in the search results table and add each of the ticked rows to the second table on the parent form.

Any and all guidance here on where to get what I need would be brilliant.

Kindest regards

DV
 
The first step is to stop thinking of your forms' UI DataGrid's as a containers for your data. E.g. you don't add items into the tables. The modern approach to programming is keeping the data (Model) separate from the UI (View) and there is some kind of logic which coordinates the interaction (eg. a Controller or a Presenter). So nowadays you'll hear about the MVC or MVP pattern.

So if you think of the UI's only job is to reflect the current state of your data, and as a way of initiating an action to change the data, then that would mean that would mean that all you need to do is change the underlying data that the UI looks at. In your scenarios above, if the parent form is looking at a particular database table or list, then your child form just needs to add items to that table or list.
 
The first step is to stop thinking of your forms' UI DataGrid's as a containers for your data. E.g. you don't add items into the tables. The modern approach to programming is keeping the data (Model) separate from the UI (View) and there is some kind of logic which coordinates the interaction (eg. a Controller or a Presenter). So nowadays you'll hear about the MVC or MVP pattern.

So if you think of the UI's only job is to reflect the current state of your data, and as a way of initiating an action to change the data, then that would mean that would mean that all you need to do is change the underlying data that the UI looks at. In your scenarios above, if the parent form is looking at a particular database table or list, then your child form just needs to add items to that table or list.

Thank you for coming back to me on this one.

Agreed, the application is pulling the data from a separate source and we are not able to add or remove from that source. The second database is what I intend to work with, so while the application can view and show me records, any editing will be applied to the second set of data. I hope this makes more sense.
 
The first thing you should do is bind your data to your UI. That has exactly zero to do with your database. You retrieve the data from the database into a local cache, which is often a DataTable, and then you bind that to your UI. The local cache, and therefore the UI, has no connection to the database. If you use DataTables and you have two with the same schema, you can call ImportRow to copy a DataRow from one table into the other.
 
Back
Top Bottom