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
AD
Administrator
Syncfusion Team
March 25, 2004 04:27 PM UTC
Check out this thread in whcih Gene suggests a solution.
http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=11311
US
uschie
March 26, 2004 09:44 AM UTC
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
AD
Administrator
Syncfusion Team
March 26, 2004 11:48 AM UTC
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.
US
uschie
March 27, 2004 01:10 AM UTC
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.
AD
Administrator
Syncfusion Team
March 28, 2004 12:13 PM UTC
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
US
uschie
March 29, 2004 02:12 AM UTC
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
>
>
AD
Administrator
Syncfusion Team
March 29, 2004 06:36 AM UTC
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
AD
Administrator
Syncfusion Team
March 30, 2004 09:00 AM UTC
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
US
uschie
March 31, 2004 06:39 AM UTC
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
AD
Administrator
Syncfusion Team
March 31, 2004 08:40 AM UTC
What problems did you run into when you tried to change it?
AD
Administrator
Syncfusion Team
March 31, 2004 09:25 AM UTC
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
AD
Administrator
Syncfusion Team
April 15, 2004 08:06 AM UTC
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 ?
AD
Administrator
Syncfusion Team
April 15, 2004 08:44 AM UTC
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;
}
}