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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Turning off dynamic sorting GridBoundDataGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

51318 Nov 2,2006 06:37 PM UTC Nov 9,2006 08:44 PM UTC WinForms 4
loading
Tags: GridControl
Mike Nohr
Asked On November 2, 2006 06:37 PM UTC

From my understanding the sorting of the gridbounddatagrid is based of the dataview.sort property.

I'm looking to extend the grid so that when the user changes a value in the sorted column the row doesn't jump and get dynamically sorted.

The requirement then is to only sort when the header of the grid is clicked or double clicked and to show the sort direction arrow (current behaviour).

I've tried override the sortcolumn function performing the following:

public override void SortColumn(int colIndex)
{
base.SortColumn (colIndex);
this.Refresh();
DataView dv = GetDataView();
dv.Sort = "";
}

Unfortunately, this not only removes the current sort but the sort arrow on the header is removed;

I found a sample that works for the GridControl

http://www.syncfusion.com/Support/user/uploads/sortColumnHeader_c211ad31.zip

I essentially need the exact same behaviour as this sample but for the gridbounddatagrid.

I've explored the idea of dynamically adding an additional hidden column and keep a sort index on that column but I'd pefer to avoid this approach if there is a easier solution.

Is there an easy way to turn off the dynamic sort of the grid?

Thanks!

Administrator [Syncfusion]
Replied On November 3, 2006 04:04 AM UTC

Hi Mike,

The attached sample implements the ListWrapper class to avoid the 'jumps' while the user changes the value in a sorted column. It also support the multicolumn sorting in a grid. Please try this and let me know if this helps.

Here is a sample.
http://www.syncfusion.com/Support/user/uploads/WrapperClassSortSample_46fcd2f1.zip

Best Regards,
Haneef

Mike Nohr
Replied On November 6, 2006 11:11 PM UTC

Thanks the sample works great except for one thing:

CurrencyManager cm = (CurrencyManager)this.dbgPOLines.BindingContext[this.dbgPOLines.DataSource];
DataView dv = (DataView)cm.List;

Now the currency manager cast returns the type of the ListWrapper class. Is there a way to have it cast to a dataview as it does by default?


>Hi Mike,

The attached sample implements the ListWrapper class to avoid the 'jumps' while the user changes the value in a sorted column. It also support the multicolumn sorting in a grid. Please try this and let me know if this helps.

Here is a sample.
http://www.syncfusion.com/Support/user/uploads/WrapperClassSortSample_46fcd2f1.zip

Best Regards,
Haneef

Administrator [Syncfusion]
Replied On November 7, 2006 12:19 PM UTC

Hi Mike,

There is no built-in property to get this. You can use the below code snippet to get the dataview from the ListWrapper class.

public DataView GetDataView()
{
PropertyDescriptorCollection tpdc = ((ITypedList)this).GetItemProperties(null);

DataTable dt = new DataTable(((ITypedList)this).GetListName(null));
for(int i =0 ;i< pdc.Count;i++)
dt.Columns.Add(tpdc[i].Name,tpdc[i].PropertyType);
for(int i = 0;i< this.Count;i++)
{
DataRowView row = this[i] as DataRowView;

if( row != null)
dt.Rows.Add(row.Row.ItemArray);
}
return dt.DefaultView;
}

Here is a modified sample.
http://www.syncfusion.com/Support/user/uploads/WrapperClassSortSample_dc4ecd.zip

Best Regards,
Haneef

Administrator [Syncfusion]
Replied On November 9, 2006 08:44 PM UTC

Again I appreciate the quick response and the solution does what we require.

I have however come across one more issue. If you use the following code to bind.

this.grid.DataSource = this.dataset;
this.grid.DataMember = this.datamember; (datatable name)

I've tried to extend the listwrapper class to suppor this using the following:

public ListWrapper(DataSet dataset, string displayMember)
{
ProcessDataTable(new DataView(dataset.Tables[displayMember]));
}

However when the grid tries to use the ITypedList Members specifically:

public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
{
return pdc;
}

an exception is thrown. (ERROR: Cannot create a child list for field "Table")

Thanks again.

>Hi Mike,

There is no built-in property to get this. You can use the below code snippet to get the dataview from the ListWrapper class.

public DataView GetDataView()
{
PropertyDescriptorCollection tpdc = ((ITypedList)this).GetItemProperties(null);

DataTable dt = new DataTable(((ITypedList)this).GetListName(null));
for(int i =0 ;i< pdc.Count;i++)
dt.Columns.Add(tpdc[i].Name,tpdc[i].PropertyType);
for(int i = 0;i< this.Count;i++)
{
DataRowView row = this[i] as DataRowView;

if( row != null)
dt.Rows.Add(row.Row.ItemArray);
}
return dt.DefaultView;
}

Here is a modified sample.
http://www.syncfusion.com/Support/user/uploads/WrapperClassSortSample_dc4ecd.zip

Best Regards,
Haneef

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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon 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.Close Icon

;