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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGridView And Deleting Rows

Status
Not open for further replies.

danielkelly

IS-IT--Management
Aug 13, 2006
28
AU
Hi,

I have a DataGridView control on a POS application I am writing as a project. I am having issues when trying to remove certain items from the control. Below is an example :-

1 Item 1 $5.00
-Extra 1
-Extra 2
1 Item 2 $10.00
1 Item 3 $2.00
-Extra 1

I want the user to be able to click on an item (or extra) in the datagridview and delete it. I can do this for single items and extras and it works perfectly (using removeat)but when I select an item, I want to check if there are any "extras" associated with the item and remove them aswell. Extras are always immediately below the item in question. My stumbling point seems to be when I remove 1 using RemoveAt, the index numbers change and I get exceptions.

This datagridview is not bound to any datasource and I am creating it on the fly.

Any help with the logic would be muchly appreciated.

Thanks,

Daniel.
 
Assuming your datagridview has three columns based on your example, if you delete the first one, the "extras" do not have an identifier in the first column.

Create a loop that keeps checking the zero (0) record of your datagridview which looks to see if an id exists in the first column. If no id, delete that row and check the next. if id, exit loop.

This loop would be executed at the same time you are performing the deletion of the row with the id...

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB.NET Programmer
 
your business logic and UI logic are tightly coupled. how you display the order shouldn't determine the behavior of the order. if you separate the logic and UI solving the problem becomes eaiser.

you have the concept of an order (or order in progress) the order contains a collection of items. an item can contain a collection of extras.
the user can remove an item from an order
by removing an item from the order you automatically remove the extras associated with the item.

all of this can be done no matter what the UI looks like. the UI just sends commands to the order saying do this or do that.

Jason Meckley
Programmer
Specialty Bakers, Inc.

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

Part and Inventory Search

Sponsor

Back
Top