Swap nodes in a linked list
Brady Kelly <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.clr |
|---|---|
| Message-ID | <[email protected]> |
Sorry if this is very obvious, but it escapes me now at a time of impending
review. I have a LinkedList<BandLine>, representing a report Band, where
BandLine is one line of text in the band, e.g. one of two detail line types,
or a header line.
I present my linked list using a DataGridView, and am trying to implement
'Move Up' and 'Move Down' commands for band lines, which involves swapping
nodes in my linked list. Now getting the BandLine to move is easy, using
ElementAt and an index provided by the grid, but to complete the swap with
AddBefore, I need a LinkedListNode at a specific index. How can I get this?
My code is as follows, and AddBefore is incomplete without the node I
mention:
private void MoveBandUp()
BandLine lowerBand =
currentBand.ElementAt<BandLine>(dgvBands.SelectedRows[0].Index);
BandLine upperBand =
currentBand.ElementAt<BandLine>(dgvBands.SelectedRows[0].Index - 1);
currentBand.Remove(lowerBand);
currentBand.AddBefore(???, lowerBand)
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com