Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
250
Howto perform autoresize on cardlabel
posted

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!

Parents
  • 469350
    Offline posted

    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.

Reply Children