Hi Mike,
I'm currently running into an issue with sizing of columns in some of my grids. I have grid bands with columns that the user cannot edit, and the columns that show in the grid cannot be resized manually by the user because I don't allow them to edit the columns. I'm depending on the grid functionality to appropriately size the columns for me. This doesn't appear to happen all the time. So I have a few questions:
Does the grid have column sizing functionality built in? Right now I have the grid setting for AllowColumnSizing set to Free, and when sizing the columns I am using PerformAutoResize to size the columns in the grid InitializeLayout event handler. That works well when the grid is drawn initially. However, if certain data is changed in other grids or forms, the size of the data in my columns can grow and the column size doesn't adjust to accommodate the larger data value. The data value ends up getting cut off toward the end. I have tried using the AfterCellUpdate event to run PerformAutoResize on the columns to resize after such a change but it does not completely work for me. The column resizes to show a little bit more of the data but not the entire data value in the column. Which leads me to my next question:
What is the best event handler to use to run PerformAutoResize (or some other function?) when a data change causes the data in my columns to grow beyond the column size? I'm using AfterCellUpdate but would InitializeRow be better or maybe some other event? The data in the column can grow quite large so could there be a width property that I need to change to allow the column size to get bigger? Something else?
If required I can attach a sample project that demonstrates the issue. I've attached some screenshots to show the problem.
Thank you,
Steve
Hi Steve,
I created a little sample that might be helpful. Perhaps it will be useful to you to work out the details in a simplified version.
I’m not sure how you are sizing the columns or restricting the user access. But I guessed that you set the Band Override AllowColSizing to AllowColSizing.Free and are then restricting specific columns by setting their AutoSizeMode to ColumnAutoSizeMode.None. You may also be limiting the size of specific columns by setting the column MinWidth and MaxWidth to a specific value. If you set those properties to the same value you would be making the column a fixed width.
I only have the “CustomertName” size restricted, ColumnAutoSizeMode set to None and limited to CellSelect.
Then I would use the AfterCellUpdate and the AfterRowUpdate events to PerformAutoResize so that after a cell or row was updated the columns were resized. You may or may not want to resize the columns during the Initializelayout.
I also added a button that performs the resizing.
Hope this helps.
Marianne
Hi Marianne ... Mike was very thorough, however, I still could not get my columns to re-size correctly. I'm suspecting it might be some inefficiency in our code or something is causing the PerformAutoResize function to not work correctly. In any case, I had to resort to hardcoding the Width property for the column for now. We will revisit the issue for our next release ... Thank you.
Just checking if you had any further questions. Looks like Mike was very through but if you had any follow-up questions, I’d be glad to help.
Please let me know if there is anything I can help with.
Steve Nugent said:if certain data is changed in other grids or forms, the size of the data in my columns can grow and the column size doesn't adjust to accommodate the larger data value.
The grid does not automatically adjust the width of the column in response to a change in the data. You have to do this in code by calling PerformAutoResize.
Steve Nugent said:I have tried using the AfterCellUpdate event to run PerformAutoResize on the columns to resize after such a change but it does not completely work for me.
This should work, assuming that the user has editing the data through the grid, and that the change in the data didn't come from the DataSource. I could be wrong, but I don't think that AfterCellUpdate will fire in response to a change that comes from the data and was not performed by editing the grid cell.
Steve Nugent said:What is the best event handler to use to run PerformAutoResize (or some other function?) when a data change causes the data in my columns to grow beyond the column size? I'm using AfterCellUpdate but would InitializeRow be better or maybe some other event? The data in the column can grow quite large so could there be a width property that I need to change to allow the column size to get bigger? Something else?
InitializeRow will fire any time any value changes in any cell of the grid, whether that change comes from the data source or from the grid. However, this is probably not a good idea, since InitializeRow tends to fire quite a lot and it doesn't give you any context as to what changed. So if you use InitializeRow, you would have to autosize every column every time the event fired, and that could be a big drain on performance.
Using AfterCellUpdate is a good idea if the cells in the grid are editable.
To track changes from the data source, you are better off using some event on the DataSource itself, if such an event exists. Or, if you know that the changes are coming from something in your code, it would be most efficient to call the PerformAutoSize when that code gets called.