Hi all!
I have an UltraGrid in CardView style, and I need to change captions of headers during runtime (for localization purposes). Also when I change captions, I want cardlabel to be automatically resized to the maximum header width to see the full text of header captions there. On our system I use this cardview ultragrid on popup form for showing details.
When I tried to make this functionality I found a strange behaviour. The cardview grid didn't resize its cardlabel when I changed caption of header and autoresized its column. But this appears only at first time form popped up. All other times I call this form - cardlabel resizes itself perfectly.
Then I tried to make small sample solution for this, but I didn't manage to reproduce it, maybe there is also some side effect of other code.
But the one strange thing regarding not auto resizing cardlabel I did reproduce. When I try to use CardLabelWidthResolved property on the band of the grid before I try to change header caption and resize column, the cardlabel doesn't make autoresize. Without touching this property - it does.
My sample code is like this:
public Form1() { InitializeComponent(); DataTable table1 = new DataTable(); table1.Columns.Add(new DataColumn("Column1")); table1.Columns.Add(new DataColumn("Column2")); table1.Rows.Add("bla", "bla"); Grid.DataSource = table1; Grid.DisplayLayout.Bands[0].CardView = true; Grid.DisplayLayout.Bands[0].CardSettings.Style = CardStyle.MergedLabels; Grid.DisplayLayout.Bands[0].CardSettings.AutoFit = true; Grid.DisplayLayout.Bands[0].CardSettings.ShowCaption = false; Grid.DisplayLayout.Bands[0].CardSettings.CardScrollbars = CardScrollbars.None; } private bool b = false; private void ultraButton1_Click(object sender, EventArgs e) { int w = Grid.DisplayLayout.Bands[0].CardLabelWidthResolved; Grid.DisplayLayout.Bands[0].Columns["Column2"].Header.Caption = b ? "Column2" : "Column2BLABLABLA"; b = !b; Grid.DisplayLayout.Bands[0].Columns["Column2"].PerformAutoResize(PerformAutoSizeType.AllRowsInBand); }
So here if I remove line: int w = Grid.DisplayLayout.Bands[0].CardLabelWidthResolved; everything is autoresized correctly, but if I leave it inside, it doesn't.
In my solution I don't have any call for property CardLabelWidthResolved, but I think it could be somehow connected or maybe caused by similar issue. And maybe there is some method for performing automatical resize of cardlabel according to its inner headers that I could call for resizing it after resizing grid columns? I use IG 2010.3 with 2056_SR.
Thanks in advance!
Hi Dmitriy,
I took a look and the PerformAutoResize method on the column does not appear to affect the card labels in any way.
It looks to me like the grid determines the appropriate width of the card labels every time the grid paints. Accessing the CardLabelWidthResolved might cause the width to get calculated prematurely.
There's no public method I can find to explicitly reset the width or re-calculate the width. But it seems like all you should have to do is Invalidate the grid.
It's hard to discuss the issue in the abstract, though. If you can reproduce the issue in a small sample project and post it here, I'd be happy to take a look at it and see exactly what is going on.
Hi, Mike!
Thank you for your fast answer!
I tried Invalidate on Grid as you suggested, but looks like it doesn't help. I also tried to look on paint event of form, and it is called multiple times, but the grid doesn't autosize cardlabel on repaint.
Regarding small sample project, the code I posted before is actually this sample project. There is just a form, ultraGrid and ultraButton, which by clicking on it changes header caption on cardview grid. And if you try it with line with CardLabelWidthResolved - you'll see that grid doesn't react on change of width in time. It resizes its cardlabel to previous value of headers width, not to the current.
But I also can post here the solution with this code itself if you like.
Hello Dave and Mike,
Thank you for the fast reaction on my issue. I've tested it with latest Service Release 2115 on WinForms 2010.3 and it now works perfectly: CardLabel autosizes itself correctly all the time. As I proposed, the issue that I could reproduce with accessing CardLabelWidthResolved did actually have the same roots with my issue on more complex system that I met during making localization, so now both my issue and issue that I found with accessing CardLabelWidthResolved are resolved.
Hello Dmitriy,
Thank you for the update. When you do confirm that the issue has been resolved, be sure to verify my previous post as the answer.
Hi, Dave!
Thank you for the information! Unfortunately, I'm not able to test the issue this moment, but I'll try to do my best next week.
Kind regards,
Dmitriy Didenko
This issue has been resolved in the latest Service Release as of the date of this post.
I have logged this as a development issue.