I have a grid control that uses a DataTable as a data source. The following line of code is present in a startup Initialize() function, as well as, in the grid control's InitializeLayout() event handler.
==> gridTable.DisplayLayout.Override.HeaderClickAction = Infragistics.Win.UltraWinGrid.HeaderClickAction.SortMulti;
I have reviewed the posts about using the BeforeSortChange() and AfterSortChange() event handlers and the sample code posted by members of the forum. I have even used the .Single option for sorting. The code samples are syntactically correct and the compiler does not complain. BUT, no matter which column header I click on at run-time to sort, I see a flicker that lasts a fraction of a second before the column REMAINS UNSORTED.
I have tried just about everything, including working with the smallest dataset (limited number of columns and rows) -- and still the same results.
I have spent so much time on this that I am now hoping that someone here can help me out. I am convinced at this point that there must be a bug in the grid when it has a "bound" data source.
Totally perplexed!!
I should also point out that that I am aware that I can specify the SortIndicator for any given column to sort manually.
It is not possible for me to set the SortIndicator because I am unable to predict which columns will be part of the underlying (bound) DataTable. I want the user to choose which column to sort on, at run-time.
Hi John,
Does the sort indicator display on the column header?
Are you sure you are using SortMulti and not one of the "External" HeaderClickAction options?
What is the data type of the column(s) that you are sorting? Sorting won't work if the column in question is a data type that is not IComparable. That's the only reason I can think of why the grid would fail to sort the column.
CASE SOLVED!!!!!!!!!
I think after all the time that I have spent working on different things, my renewed approach to the unbound column has worked!!
I am now able to sort and to use the unbound RowID column without any issues.
Thanks Mike!
GOOD NEWS - If I disable my "RenumberGridRows()" statement in the AfterSortChange() event, my grid now sorts!!!!!!!!!!
My only way to have my cake and eat it too is if I can find a way to implement my RowID column as an "unbound" column and be able to successfully display my row id values in the cells. I will take another stab at it myself but if you have a more readily available idea as to how to resolve my dilemma, I would love to hear it!
Thanks for your help Mike!!! This has been a nuisance for many days now and I finally feel close to a solution.
I think I now know at least what part of the problem is.
I have a column in my database called "RowID" which I was forced to create because UltraWinGrid.UltraGrid does not play nice when it comes to unbound columns and bound columns. I have implemented "Page x of y" in my table to manage extremely large datasets by displaying 250 records at a time. Since a user might be on Page 2 of Y (e.g., record 251 to 500), I needed a way to show the row numbers accurately. As a result, each time the page is changed, I have to calculate the row numbers in code, then update the DataTable -- before re-binding the data source.
Due to this behaviour, any time a user clicks on the header of a column, my AfterSortChange() event is called which in turn calls the "RenumberGridRows()" function. This function "detaches" the datasource in order to update the RowIDs in the DataTable before re-attaching the DataTable as a datasource. When these steps take place, it forces the code in the InitializeLayout() event to be called each and every time.
It also happens that my InitializeLayout() routines recalls the user's last preferred 'column positions' which forces my column positions to continually be reset to their original positions ---->> a royal pain when a user (a) MOVES a column, then (b) clicks on a column to sort.
The long story here is that each time I click on a column (to sort), my RenumberGridRows() event fires the original SQL query which is "ORDER BY ActivityTime ASC".
This vicious cycle is all due to the fact that the UltraWinGrid.UltraGrid won't let me manage the RowID any other way. I tried an unbound column before but it would never allow me to update its contents because the rest of the grid was "bound" to a DataTable.
Since I finally have a clue as to the underlying cause, do you have any ideas or suggestions on how I might be able to implement my row numbering scheme without using a RowID column in my database and editing the DataTable on each new page request??? There's got to be a way. If it is possible to add a RowID column as UNBOUND to the grid after defining my data source, then I need to figure out why I am unable to get the cell contents (for RowID) to appear. All my past attempts showed a RowID of empty, blank cells.
I appreciate your patience and your code sample really helped me understand my real issue. Hopefully there's light at the end of the tunnel.
There are a lot of very confusing things in your post. I don't understand why you are having so much trouble with this, because it really is very simple. So something very strange must be going on in your application that is causing this not to work.
The first thing I'm wondering is... are you sure you are using UltraGrid? You are using a lot of terms here that do not actually exist in the UltraGrid control. For example, there is no "ExtendedSortMulti", nor is there an event called "BeforeSort" or "BeforeSortEvent".
Maybe you meant "ExternalSortMulti" and "BeforeSortChanged". But I am pretty sure "ExternalSortMulti" is not what you want here. I assume you want the grid to perform the actual sorting of the data for you and not to do your own sorting. The "External" actions don't do any sorting, they are there so that you can show the grid's sorting UI, but do the sorting yourself. So you probably want either HeaderClickAction.SortMulti or HeaderClickAction.SortSingle.
Also, I'm pretty puzzled about this post you refer to where I recommend adding every column to the SortedColumns collection. That would be a very odd thing to do under normal circumstances and I can't imagine any situation in which I would have recommended that. If I did post that, it must have been in order to do something very strange and unusual.
Anyway, I have attached a small sample project here where clicking on a column header in the grid sorts the data and it works just fine. I also added a button to the form which sorts a couple of columns in code. As I said, it's very simple, so if this is not working in your application, then something odd is going on. The only thing I can think of is that your DataTypes aren't what you think that are. Have you checked the DataType of the column(s) at runtime to make sure they are actually simple strings and integers and not some unusual type that doesn't support comparisons?
Hi Mike,
The ONLY way I can get the indicators to show up in the headers is if I add ALL columns to the SortedColumns() collection.
I have used "SortMulti" and "ExtendedSortMulti" and neither work.
My data types are simple "strings". Some columns are simple "integers".
The BeforeSortEvent() is unfortunately rather useless because there is no reference to the Header being clicked on. I came across your reply to a post on this topic from a few years ago and that's how I came across your suggestion to "add every column" to the SortedColumns() collection. Personally speaking, I find this implementation rather counter-intuitive. One would expect a collection of "SortedColumns" to contain ONLY a list of "sorted columns".
I don't understand how the UltraWinGrid can be so counter-intuitive when it comes to this one simple, yet common feature. Here is what I am expecting to be able to do:
1 - Create a DataTable that holds my dataset obtained from an SQLite database.
2 - Attach the DataTable to my UltraGrid as a DataSource.
3 - Let the user click on any header of the grid to sort. When this happens, I have an expectation for the Ascending indicator to appear. If the user clicks on the same column header again, it will change to a Descending indicator. If the user holds down the SHIFT key while selecting columns, then the group of selected columns are sorted.
Here's what I don't understand about the UltraGrid and the various facts or pieces of information that I can find:
1 - I can use the SortIndicator property implicitly in a column to sort. For this to happen, I have to have the HeaderClickAction set to SortMulti.
2 - If I want to handle the sorting myself in some unwanted or crazy fashion, I have to set HeaderClickAction to ExtendedSortMulti. If I do this, the current Event handlers in the UltraGrid are inadequate to properly manage the SortedColumns collection. Like I said, why is there not a simple "BeforeHeaderClick" event or something similar that gives up the name and ordinal position of the column clicked?????? This is the first expectation most of us would have.
3 - I suspect that I can sort properly if I use the grid in virtual mode. Not sure why that is but I suspect it might be because the grid is not bound to a datasource.
I am sorry for running on and on but my mind, at this point, is totally confused.
I've tried every which way to sunrise. Nothing works.
Do you think it might be easier if you could post a simple "start to finish" code sample that proves to me that this can actually be done?? I would be indebted to you!!!!!!!!!!!!!!!!!!!!!!