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
235
UltraGridRow, strange behavior from PerformAutoSize() ?
posted

Hi,

I previously made a post asking about the multiline display for a single row. It worked fine in my mini project. But now that i want to implement that feature into the main software, i get some weird behavior.

I found a work around to my problem by calling PerformAutoSize() 2 times to get the expected result, else it doesnt work. :(

foreach (UltraGridRow row in e.Layout.Rows.All)
{                  
row.PerformAutoSize();
row.PerformAutoSize();
}

Maybe you can see the problem already there but i will be adding codes that happen in the event InitializeLayout. I tried to get the most related lines of code. Here it is :

            this.SuspendLayout();
            this.BeginUpdate();

           e.Layout.CaptionVisible = DefaultableBoolean.False;

            e.Layout.Override.RowSelectorHeaderStyle = RowSelectorHeaderStyle.None;
            e.Layout.Override.RowSelectors = DefaultableBoolean.False;
            e.Layout.Override.ActiveAppearancesEnabled = DefaultableBoolean.False;

            e.Layout.Bands[0].Override.AllowAddNew = AllowAddNew.No;
            e.Layout.Bands[0].Override.AllowDelete = DefaultableBoolean.False;
            e.Layout.Bands[0].Override.AllowUpdate = DefaultableBoolean.False;

            this.DisplayLayout.Override.WrapHeaderText = DefaultableBoolean.True;
            e.Layout.Bands[0].Override.AllowRowLayoutCellSizing = RowLayoutSizing.Both;
            e.Layout.Bands[0].Override.CellClickAction = CellClickAction.CellSelect;
            e.Layout.Bands[0].Override.SelectTypeCell = SelectType.Extended;

            e.Layout.Override.HeaderClickAction = HeaderClickAction.Select;
            e.Layout.Override.SelectTypeCol = SelectType.None;
            e.Layout.Override.SelectedCellAppearance = e.Layout.Override.HotTrackHeaderAppearance;
            e.Layout.ScrollStyle = ScrollStyle.Immediate;


            foreach (UltraGridColumn column in this.DisplayLayout.Bands[0].Columns)
            {
                if (column.Tag is IEntete)
                {
                    IEntete entete = (IEntete)column.Tag;
                    if (column.Width < entete.EnteteSource.TO.Largeur || entete.EnteteSource.TO.Largeur == column.MinWidth)
                        column.RowLayoutColumnInfo.PreferredCellSize =
                            new Size(entete.EnteteSource.TO.Largeur, column.RowLayoutColumnInfo.PreferredCellSize.Height);
                }
            }

this.DisplayLayout.Bands[0].RowLayoutStyle = RowLayoutStyle.ColumnLayout;

                e.Layout.Override.RowSizing = RowSizing.Free;

                foreach (UltraGridColumn column in e.Layout.Bands[0].Columns)
                {
                    column.AutoSizeEdit = Infragistics.Win.DefaultableBoolean.True;
                    column.CellMultiLine = Infragistics.Win.DefaultableBoolean.True;
                }


                foreach (UltraGridRow row in e.Layout.Rows.All)
                {
                    row.PerformAutoSize();
                    row.PerformAutoSize();
                }

 

this.EndUpdate();
this.ResumeLayout();

 

If you want more info on my problem, i can send more code. Note : I don't use any events that could interact with the UltraGrid other than the InitializeLayout.

 

 

Parents
  • 469350
    Offline posted

    Hi,

    What version of the grid are you using?

    And in the code you have here, what is "this"? Is this an inherited grid control, or is this the form?

    I don't see anything wrong with this code, so my best guess is that doing this in InitializeLayout is too early.

    It's also not very efficient to loop through all of the rows in the grid, anyway. You might be better off calling PerformAutoSize in the InitializeRow event, or if you must loop, do it immediately after setting the DataSource/DataMember on the grid instead of inside InitializeLayout.

  • 235
    posted in reply to Mike Saltzman

    Hello, i use UltraGrid v10.2.

    Here is a little project containing this behavior :

    The MultiLine display works after editing the cells but not before, even by the 3 events i use.

    If you dont have time to open this file, here is the main code :

    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                string[] test = new string[2];
                test[0] = "test";
                test[1] = "testtt eeee eeeeee eeeee ee";
                this.ultraDataSource1.Rows.Add(true, test);
               
            }

            private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
            {
                this.ultraGrid1.SuspendLayout();
                this.ultraGrid1.BeginUpdate();

                this.ultraGrid1.DisplayLayout.Override.CellMultiLine = DefaultableBoolean.True;

                foreach (UltraGridCell cell in this.ultraGrid1.DisplayLayout.Rows[0].Cells)
                    cell.CellDisplayStyle = CellDisplayStyle.FullEditorDisplay;

                this.ultraGrid1.DisplayLayout.Bands[0].RowLayoutStyle = RowLayoutStyle.ColumnLayout;
                e.Layout.Override.RowSizing = RowSizing.Free;

                foreach (UltraGridColumn column in e.Layout.Bands[0].Columns)
                    column.AutoSizeEdit = Infragistics.Win.DefaultableBoolean.True;

                foreach (UltraGridRow row in e.Layout.Rows.All)
                {
                    // For the PerformAutoSize() to works, you need to uncomments those 2.
                    //row.PerformAutoSize();
                    row.PerformAutoSize();
                }

                this.ultraGrid1.EndUpdate();
                this.ultraGrid1.ResumeLayout();
            }


            private void ultraGrid1_AfterColPosChanged(object sender, AfterColPosChangedEventArgs e)
            {
                foreach (UltraGridRow row in this.ultraGrid1.Rows.All)
                {
                    //This line doesn't work.
                    row.PerformAutoSize();
                }
            }

            private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
            {
                //This line doesnt work. Adding more PerformAutoSize() won't work either.
                e.Row.PerformAutoSize();
            }
        }

Reply Children