hello all,
I got a quick question about the UltraWinGrid.
i have X amount of column in a grid, for this exemple let's say 2.
All i am looking for is the grid to AUTOSIZE each column either with:
the caption if its bigger than its content,
or its content if its caption is smaller.
So basicaly, if col 1 has for caption - Administration, and the content are Letters, i want the grid to autosize the col to the size of "Administration"
and if col 2 has for caption - Items, and the contents are numbers looking like : 3238495843964885934568, i need the col to autosize to the largest number.
Thank you in advance,
John
Hi John,
Call the PerformAutoResize(AllRowsInBand) method on each column. A good place to do this is in the InitializeLayout event of the grid.
hey mike,
Thx for the response, i will try it right now!
Hi Mike
What version are you using for this to work?? I cannot get the columns to resize correctly using this method - everything resizes to the column header's width and not the width of the largest value in the cells (when the cell values in some columns is clearly greater than the column header caption in my example). I am using v8.2
The data is loaded via a standard bindingsource/tableadapter method and there is only one table (one band) in the datasource.
Any suggestions??
You're probably not calling the correct overload of PerformAutoResize. By default, this method only resizes the colmuns based on the the visible rows. In InitializeLayout, there will be no visible rows, so it's only using the headers. There's an overload to force it to size based on all the rows in the band, though, so make sure you use that one.
Hi Mike...
This is the VB.NET code I'm using...(should've posted that earlier - sorry!)
Private Sub grid_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles grid.InitializeLayout For Each col As UltraGridColumn In e.Layout.Bands(0).Columns col.PerformAutoResize(PerformAutoSizeType.AllRowsInBand) NextEnd Sub
I also only have about 5 rows in the grid so all rows are visible (eg: no scrollbars). Is this not the correct way to call the PerformAutoResize method?
DatanetAP said:This is the VB.NET code I'm using...(should've posted that earlier - sorry!)
That makes no difference at all. :)
DatanetAP said:I also only have about 5 rows in the grid so all rows are visible (eg: no scrollbars).
They are not visible when InitializeLayout fires, because the grid has not painted, yet.
DatanetAP said:Is this not the correct way to call the PerformAutoResize method?
Yes, the code you have here appears correct. If this is not working, then my best guess is that you are setting the DataSource of the grid to an empty data source and then InitializeRow fires, and then you are adding rows to the data source after the AutoSize has completed.
If that's not the case, then I don't know what's happening, and you should try to duplicate the behavior in a small sample project and Submit an incident to Infragistics Developer Support so they can check it out.
Mike,
I'm right here....I am setting the DataSource of the grid to an empty data source, on my form's shown event I am getting the data and merging it into a datatable which has been bound to the grid. So how can I get these columns re-sized from here?
Thanks.
I've said a little prayer for you Mike, I know it must be hard fielding "stupid" questions all day! :)
Here's what of course, you knew....but I had forgotten-- "DisplayLayout" and without that I couldn't figure out how to get it to work. Maybe my company should have sprung for some training, but alas, it was not to be. Amazing how the you can wade through sometimes without knowing some of the critical information! Anyway, I put this right after the data is populated and it works great!
{
}
You need to call PerformAutoSize after the data has been added.