...or are c# listviews really such a nightmare to manage?
Okay the problem I'm working on is very simple. Or at least it appears to be so:
I have a text file which contains information about customer orders on separate lines. The data items are separated by semi-colons.
My form iterates through these orders, puts the item information into hashtables and puts each hashtable into a master hashtable. Some summary information about each order (product/order#/customer name/customer#) is displayed in my listview separated by sortable columns. Below the listview is a tab control with textboxes for the editable parts of the order details spread across three tabs.
Here is what I would like to happen:
- User clicks on single entry: tab control textboxes fill with Order Details.
- User edits details in tab control.
- User clicks on another order: confirmation message checks that the change should be committed, if "Yes" then the details should be saved back to the relevant Hashtable and the display in the listview updates.
- User selects multiple listview items: the top item should be editable in the tab control.
- User presses "Remove Item(s)" button on a tool strip at the top of the form: the item(s) are removed from the hashtable and the listview control is updated to reflect the deletion. The textboxes are all set back to blank across the tab control.
This seems to me like pretty ordinary and reasonable behaviour. I guessed that using the SelectedIndexChanged event would offer the opportunities to do the data work. But the event fires twice on every selection/deselection and it's not always clear which items should be updated in the listview at which point.
The code for testing what kind of "selection/deselection" has just taken place and decide what action should thus be taken is starting to get quite long and I'm just wondering if I'm making things too complicated.
So:
- Is there another event I could use to achieve my functionality goals? Or
- Is there something about the SelectedIndexChanged event that I don't know that would help the program decide what it should be doing at any given point? Or
- Am I just going about this the wrong way?
Any suggestions, even ones about redesigning my form would be most welcome.
EDIT: While trying to attack this problem from a different angle I am changing my master hashtable to a sortedlist. The rest of the problem remains the same.