Hello,
I have a custom pin/unpin columns menu in the header. On clicking the item the following gets called.
ultraGridPosition.DisplayLayout.Bands[0].Columns[columnKey].Header.Fixed = true;
but the AfterColPosChanged event does not fire. I need to capture an event when the columns re-arrange on the grid and get the column order.
Thanks,
Vijayan
Hi Vijayan,
Some events only fire in response to user action and do not fire when something is changed in code.
The idea is that if a user changes something, you need an event to tell you that it happened. But if you change something in code, you know you did it and you don't necessarily need an event to tell you.
So typically what you would do in a case like this is take your code out of the AfterColPosChanged event and put it into a method. Then call that method from the AfterColPosChanged event and also from anywhere else in your code that changes the fixed state of a header.
Thanks Mike.
I tried using the function but whats happening is that the function gets called before the column re-arranges and hence the visibleposition value is incorrect.
Say I have 14 columns, the first 4 are pinned and I then pin the 12th column by setting value to the fixed in header in a custom function. I called the other function right after this. But the column is yet to re-arrange and the function executes, giving the incorrect col position value. The column re-arranges later and the event is not fired but the function has already executed. Is there a way I can call the function after the columns re-arrange?
I call the function from both the event handler and the custom pin function.
Hi,
May I ask why you want to read out the VisiblePositions of the columns? That seems like an odd thing to do, especially immediately after changing them.
If you are doing it in order to save the layout of the grid, then it would be a lot easier for you to use the built-in Save and Load methods on the grid's DisplayLayout, rather than writing a lot of code yourself.
I tried this out in the way you describe and I am not getting the same results.When I examine the VisiblePosition on each column header immediately after setting the Fixed property on one header, the header I changed shows the correct (new) VisiblePosition.
So in my sample I have 14 columns. Here are the initial column keys and the VisiblePosition of each:
Key: 0 (Fixed)String 1: 1 (Fixed)String 2: 2 (Fixed)String 3: 3 (Fixed)String 4: 4String 5: 5String 6: 6String 7: 7String 8: 8String 9: 9String 10: 10String 11: 11String 12: 12String 13: 13
Now I call this code:
this.ultraGrid1.DisplayLayout.Bands[0].Columns[12].Header.Fixed = true;
And immediately after that line of code I display the VisiblePositions again.And I get this:
Key: 0 (Fixed)String 1: 1 (Fixed)String 2: 2 (Fixed)String 3: 3 (Fixed)String 4: 5String 5: 6String 6: 7String 7: 8String 8: 9String 9: 10String 10: 11String 11: 12String 12: 4 (Fixed)String 13: 13
I have attached my sample project here so you can see if you get the same results.
Thanks Mike. Please Ignore.
I see whats happening. I have two bands, when the column moves the seperator does not move in the child band. Hence it gives a feeling that the column has not moved in the childband.
I fixed by pinning the childband. What was happening that the parent was pinned but the child was not.