We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

sorting in a databound grid

Thread ID:

Created:

Updated:

Platform:

Replies:

12261 Mar 24,2004 09:21 PM Apr 15,2004 04:44 AM Windows Forms 13
loading
Tags: GridControl
uschie
Asked On March 24, 2004 09:21 PM

I have a databound grid which has default sorting. When I sort on a particular column, make changes & save, the sorting gets refreshed. How can it be restored to the last sort order, even after making changes & saving, until the form is closed . Please suggest

Administrator [Syncfusion]
Replied On March 25, 2004 11:27 AM

Check out this thread in whcih Gene suggests a solution. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=11311

uschie
Replied On March 26, 2004 04:44 AM

Thanks anyway.Tried this. Seems quite complicated. Is there some simpler method for doing this.Please suggest if there''s a shorter way of sorting the databound grid (after making changes & saving ) >Check out this thread in whcih Gene suggests a solution. > >http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=11311

Administrator [Syncfusion]
Replied On March 26, 2004 06:48 AM

There is no simple way that I know to do this. The GridDataBoundGrid just displays what your DataSource presents it. And it is the DataSource that is shuffling these added rows. Any solution would have to undo/intercept what the DataSource is doing, and this is where the complications come in. I will try to prepare a sample that wraps the complications into a an object that you can use in a simple manner.

uschie
Replied On March 26, 2004 08:10 PM

Thanks for all this. Just telling you that I''m working on VB.Net >There is no simple way that I know to do this. The GridDataBoundGrid just displays what your DataSource presents it. And it is the DataSource that is shuffling these added rows. Any solution would have to undo/intercept what the DataSource is doing, and this is where the complications come in. > >I will try to prepare a sample that wraps the complications into a an object that you can use in a simple manner.

Administrator [Syncfusion]
Replied On March 28, 2004 07:13 AM

Below is a sample. It has a file, SortBlocker.vb, that defines an object that you can wire to your grid that will block the sorting an new rows are added to a sorted GridDataBoundGrid. This does add a column to your DataTable, so you should Unwire the grid before you call DataAdapter.Update to flush the changes to your datasource. When you sort, it changes the values in the new column to reflect the row''s sort position, and then sorts on this column. This does take some time, but if your table has hundreds of rows, it is probaly not an issue. But if it has thousands of rows, then this solution is probably not suitable. FreezeSortedGDBG_640.zip

uschie
Replied On March 28, 2004 09:12 PM

Thanks in anticipation. I''d like to re-explain my problem . I have a databoundgrid . On form load data gets loaded onto it from the database. The grid is not editable. There is a entry region next to the grid on the same form,where textboxes are used to disply/edit/enter new data. There''s a save button, on clicking which the data goes to the database & is reloaded in the grid. So now I click on the column(say 2nd one),the data in grid gets sorted .Then I click the 3rd row, data gets loaded in the textboxes,I edit it & click save. The sort order which existed before clicking save gets lost. I''d like to get the order of sorting preserved after save also. Pl.suggest >Below is a sample. It has a file, SortBlocker.vb, that defines an object that you can wire to your grid that will block the sorting an new rows are added to a sorted GridDataBoundGrid. > >This does add a column to your DataTable, so you should Unwire the grid before you call DataAdapter.Update to flush the changes to your datasource. When you sort, it changes the values in the new column to reflect the row''s sort position, and then sorts on this column. This does take some time, but if your table has hundreds of rows, it is probaly not an issue. But if it has thousands of rows, then this solution is probably not suitable. >FreezeSortedGDBG_640.zip > >

Administrator [Syncfusion]
Replied On March 29, 2004 01:36 AM

The same techique will probably work, but you need to handle the ItemMoved case in ListChanged. Here is the sample modified to to this. There is also some code in the button handler on the form where you do the save to try to avoid some flickering. FreezeSortedGDBG_VB_1203.zip

Administrator [Syncfusion]
Replied On March 30, 2004 04:00 AM

Thanks a lot,it was fabulous,it solve 60% of my problem,but unfortunatelly there is one more thing. I am not using binding for the text box like this: Me.TextBox1.DataBindings.Add("Text", Me.gridDataBoundGrid1.DataSource, "LName") instead of this,on "RowEnter" event of grid i fetch the RowIndex and correspondinglly load data in textbox. can u modify ur code according to above case

uschie
Replied On March 31, 2004 01:39 AM

Thanks a lot,it was fabulous,it solve 60% of my problem,but unfortunatelly there is one more thing. I am not using binding for the text box like this: Me.TextBox1.DataBindings.Add("Text", Me.gridDataBoundGrid1.DataSource, "LName") instead of this,on "RowEnter" event of grid i fetch the RowIndex and correspondinglly load data in textbox. can u modify ur code according to above case

Administrator [Syncfusion]
Replied On March 31, 2004 03:40 AM

What problems did you run into when you tried to change it?

Administrator [Syncfusion]
Replied On March 31, 2004 04:25 AM

To get the sample to work using RowEnter, I commented out the line of code you showed, and add this code to a RowEnter event handler. if e.RowIndex > 0 then Me.textBox1.Text = me.gridDataBoundGrid1(e.RowIndex, 2).Text End if

Administrator [Syncfusion]
Replied On April 15, 2004 04:06 AM

Can the order of sort, ie. the last order (ie.ascending or descending)in which it was sorted on a column of a databound grid be retrieved ?

Administrator [Syncfusion]
Replied On April 15, 2004 04:44 AM

There Tag object in the header cell of the last sorted column holds the SortDirection of the sort. But there is no property that gives you the actual last sorted column, so you would either have to maintain a LastSortedColumnIndex yourself somehow (there CellClick or CellDoubleClick), or you could just loop through and find it. int sortDir = 0; for(int i = 1; i <= this.grid.Model.ColCount; ++i) { if(this.grid[0,i].Tag != null) { if(((ListSortDirection)this.grid[0,i].Tag) == ListSortDirection.Desc) sortDir = -1; else sortDir = 1 } break; } }

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;