Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manually Adding Rows to a DataGridView

Status
Not open for further replies.

ChewDoggie

Programmer
Mar 14, 2005
604
US
Hello All,

I have a Windows form that has two datagridview controls on it (dgAvailableParts and dgSelectedParts). I'm suppose to allow the user to double-click on the parts in each list to move the parts (back and forth) between the two DGV's.

Because of this manual moving of items between the two controls, I cannot bind either of the controls.

I have a dataset that has been populated from a query. I need to load one of the dgv controls by looping thru the dataset, but don't know how to do this.

Can someone give me some examples of how to do this?

Chew


10% of your life is what happens to you. 90% of your life is how you deal with it.
 
Add the item to the underlying datasource and bind the grid.
This will be much easier than binding sometimes and adding others.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
If I understand correctly:

If I remove an item from the bound list, then I should remove the item from the dataset and then rebind to the control ?

And If I add an item to the bound list, then I should add the item to the dataset and rebind to the control?

Correct ?

Chew


10% of your life is what happens to you. 90% of your life is how you deal with it.
 
I've never added/removed items manually from a dataset.

I guess I could google that.

C.


10% of your life is what happens to you. 90% of your life is how you deal with it.
 
yes. the UI layer should be as thin as possible, pushing as much logic into the core of the application as possible. the UI is just displaying the data found in the list that it is bound to. the actual data management is happening beneath the UI in the application domain.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
The trick here is that nothing is going back to the datasource, its all read-only. But I get the gist.

Thank you !

C.


10% of your life is what happens to you. 90% of your life is how you deal with it.
 
The trick here is that nothing is going back to the datasource, its all read-only. But I get the gist.
this is dependent on how you structure your code.

I would approach it like this:
1. query database
2. map records to a collection of view model objects
3. add the additional data to the collection
4. bind to UI
with these layers in place the view model has no knowledge of the database. so the changes will not be persisted.

when the time comes to save the changes. I would map the view model objects to the database and save. if I need to abort I just clear the list and start over.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top