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

Moving rows/records up or down in a grid...

Status
Not open for further replies.

TerDavis

Technical User
Sep 18, 2002
36
0
0
US

Hello,

I have a grid that is bound to a datatable.
I want the user to be able to move an item ( row )
in the grid up or down.

So I created an Up and Down button and in the
UP button i basically do the following :

indx = grid.currentrowindex;

I create a new record in the recordset and
than i copy the fields from the currently selected
record over...

wavRow["Name"] = this.campaign.Data.AUWave.Rows[indx]["Name"];
wavRow["Description"] = this.campaign.Data.AUWave.Rows[indx]["Description"];
wavRow["TypeCD"] = this.campaign.Data.AUWave.Rows[indx]["TypeCD"];

I than delete the record in the record set...
//Remove the current row
this.campaign.Data.AUWave.Rows.RemoveAt(indx);

and than i INSERT the new ( saved record ) into
the recordset ....

This seems to work IF you are looking at the datatable and the rows, the record is in the new postion, one up from its previous position...
The problem seems to be that the grid is not refreshing ...

Is there a better way to move the records up or down in
a grid ???

-ter


 
Ter,
How are you binding and refreshing the datagrid?

JC

Friends are angels who lift us to our feet when our wings have trouble remembering how to fly...
 
Hey JCruz,

I am using the DataSource property of the grid...
I have tried the refresh and suspend....and
I have even reset the DataSource to no avail...

I am also not sure if i using the correct approach...

-ter
 
TerDavis,

How you are determining the order in which the rows have to be displayed. I am guessing that you should be having something like a sequence_num right? If so the best approach is just swap the sequence_num each time the user is clicking UP/DOWN arrow. The problem with your approach would be adapter will create that many INSERTS/DELETES to the backend as much as user clicked on the button, where as swapping the sequence_num will always be an UPDATE.

We used grid.SuspendLayout/grid.ResumeLayout and that worked fine for us.

-Kris
 
I can see concurrency having a HUGE impact here. What if as user wishes to swap two rows. Then another user wishes to swap with one of those same rows. Only on his screen, the first 2 rows still have their old positions.
 
RiverGuy,

It is same as with any normal screen. Say if you have a customer screen when two users are editing the same customer at the same time. How would you go about with handling that? The same thing you need to do here as well. I don't see that it is any different than that.

-Kris
 
The editing customer scenario doesn't matter as much to me. Its not as big of a deal, because changing one customer doesn't affect other customers.

The only solution here is to allow one user at a time work with these settings. He is wanting to allow the users to modify every single record in the table on one screen.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top